Explore BrainMass

Shell scripting: Few parameter expansion related questions

Give brief answers for the following questions.

1. Can an until loop sometimes never execute?

2. Will the following script execute with no errors?

for I
echo $I

3. Does the following script print to standard output, a list of numbers equal to the number passed on the command line?



while [ "0$index" -le $count ]
echo $index
index=`expr "$index" + 1`

4. Will the following statement print 'I am glad this class is over' to standard output if the shell variable XYZ is NULL or not set?

: ${XYZ:?"I am glad this class is over"}

5. After the statement

: ${VISUAL:=vi}

will the value of the shell variable VISUAL always be vi?

6. Will the following command execute:

${VISUAL:+vi} ls

the command 'ls' if the shell variable VISUAL is not set or null?

7. Will the following commands send to the line printer all files whose contents contain the text '/bin/sh' if the command to print is lpr ?

MATCH=`grep -l '/bin/sh' *`
lpr ${MATCH?"NO files found"}

Solution Preview

1. Yes, sometimes an until loop will never execute. Consider the example given below.

until [ $myvar ...

Solution Summary

Solution also gives reasons/examples in many cases.