简体   繁体   中英

Shell scripting output

What will be the output of the following script?

#!/in/bash

secondLoop="A B C D E F G"
counter=0

for a in 6 7 8 9
do
for b in "$secondLoop"
do
let "counter+=1"
 done
done
echo "This script has $counter iterations"​

Options:

  1. This script has 28 iterations.

  2. This script has 21 iterations.

  3. This script has 4 iterations.

  4. This script has 0 iterations.

It should be 4 iterations, because there are quotes in

for b in "$secondLoop"

so that the variable is expanded to a single value (that included spaces).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM