I am having problem when trying to assign a value to a variable in a loop. It will be like using variable inside a variable. So I created an array to add the values still something is not right.
Please take a look at the following KornShell (ksh) script and let me know where did I mess up
#!/usr/bin/ksh
set -A array $1 $2 $3
set -A values
typeset -i a
a=0;
for files in ${array[@]}
do
cd ~/shell_lib
ls | grep $files
${values[$a]}="$(cksum $files)"
a=$a+1
done
echo ${values[@]}
OUTPUT
$ ./intarray.sh forall.sh name.sh
forall.sh
./intarray.sh[12]: =3311936491 251 forall.sh: not found
name.sh
./intarray.sh[12]: =3294813710 338 name.sh: not found
The file is there and it has done the cksum, but still it says not found! I can not understand what is wrong! Any insight?
This is almost certainly not what you want. Try:
${array[index]}refers to thevalueof the (still empty) array entry, so the original lineresults in the shell trying to execute
="$(cksum $files)".