I have a shell script that gets called like this
ex file1 file2 file3 word1 word2 .... wordn
I what to have file1 file2 file3 in an array and I tried the following
for i in $(seq 1 3)
do
FILES[$i]=$0;
` expr shift `;
echo "FILES["$i"]="$FILES[$i];
done;
So I want in a sequence to shift 3 times the arguments and save them like this...but it gives me the error :
./ex: 11: ./ex: FILES[1]=./ex: not found
FILES[1]=[1]
./ex: 11: ./ex: FILES[2]=./ex: not found
FILES[2]=[2]
./ex: 11: ./ex: FILES[3]=./ex: not found
FILES[3]=[3]
Also I tried like this :
for i in $(seq 1 3)
do
FILES[$i]=$i; // this actually means 1,2 or 3;I would like to mean $1,...
` expr shift `;
echo "FILES["$i"]="$FILES[$i];
done;
To make it be $1 not 1 I tried something like $($i) or ${$i} but says is bad substitution . Thanks !
files. All-uppercase names are reserved for builtins and environment variables; when you use them for your own purposes, you risk overwriting an environment variable by mistake.seqis a nonstandard command.for ((i=1; i<3; i++)); dowould be the more portable (within platforms having bash, not POSIX sh) and efficient approach, working on platforms that don't haveseq, and not having the overhead of starting an external program just to count some numbers!