mirror of https://github.com/tLDP/LDP
25 lines
591 B
Bash
25 lines
591 B
Bash
#!/bin/bash
|
|
# csubloop.sh: Setting a variable to the output of a loop.
|
|
|
|
variable1=`for i in 1 2 3 4 5
|
|
do
|
|
echo -n "$i" # The 'echo' command is critical
|
|
done` #+ to command substitution here.
|
|
|
|
echo "variable1 = $variable1" # variable1 = 12345
|
|
|
|
|
|
i=0
|
|
variable2=`while [ "$i" -lt 10 ]
|
|
do
|
|
echo -n "$i" # Again, the necessary 'echo'.
|
|
let "i += 1" # Increment.
|
|
done`
|
|
|
|
echo "variable2 = $variable2" # variable2 = 0123456789
|
|
|
|
# Demonstrates that it's possible to embed a loop
|
|
#+ inside a variable declaration.
|
|
|
|
exit 0
|