The problem in your previous post was this: the shell has to decide what is an argument and what are several arguments. Usually the space character (or any other whitespace for that matter) is used for that:
mv filea fileb
is interpreted as to take a file "filea" and rename (mv) it to "fileb". But lets suppose you have a file with whitespace in its name, how would you make the shell aware that
mv partone parttwo new name
should mean to take a file called partone parttwo and rename it to new name? How can the shell decide that you are not talking about 4 filenames, each separated by a blank or a file named partone parttwo new which should be renamed to name, etc.?
This is done by enclosing strings into double quotes. This groups the strings and make the shell aware where the boundaries are, even when the expression would be ambigous otherwise:
mv "partone parttwo" "new name"
This version removes all ambiguity.
In light of this lets consider your first line:
VALUES="1000 2000 3000"
for VAL in "${VALUES}"; do
The first thing the shell does is to replace the "${....}" with the content of the variable, so you commandline reads, after this:
VALUES="1000 2000 3000"
for VAL in "1000 2000 3000"; do
And now you should see the problem: you present a SINGLE element to "for" and therefore get a single pass of your loop. Removing the double quotes would do the trick:
VALUES="1000 2000 3000"
for VAL in ${VALUES}; do
This of course would mean that your values should not contain any whitespace, because the shell would split them and interpret them as two distinct values. To overcome this you should use an array and a while-loop:
array[0]="1000"
array[1]="2000"
array[2]="3000"
array[3]="4000"
array[4]="5000"
array[5]="ab cd" # notice the whitespace
array[6]="6000"
iCnt=0
while [ $iCnt -lt ${#array[@]} ] ; do
echo "array element number $iCnt is: \"${array[$iCnt]}\""
(( iCnt += 1 ))
done
Regarding the "conditional compilation": there is no such thing, because bash is an interpreted language. You could write any garbage into the program code, as long as there is no attempt to execute it would never show:
if [ 1 = 0 ] ; then
this is never going to be executed
and it does not matter that this makes no sense at all as a
bash-script
else
echo "would you exchange the if- and else-branches"
echo "you would get several errors"
fi
I hope this helps.
bakunin