Things under legendu
Fish Shell is preferred to Bash/Zsh. The following content is for Bash/Zsh only.
Tips and Traps¶
Forggeting
$is a common mistake when using a shell variable.
%%bash
for x in 1 2 3 4 5; do
echo $x
done1
2
3
4
5
%%bash
for x in {1..5}; do
echo $x
done1
2
3
4
5
%%bash
for x in {1..5..2}; do
echo $x
done1
3
5
%%bash
for x in $(seq 1 2 5); do
echo $x
done1
3
5
%%bash
for (( i=1; i<=5; i++ )); do
echo $i
done1
2
3
4
5
%%bash
for (( i=1; i<=5; ++i )); do
echo $i
done1
2
3
4
5
Below is an infinite loop.
%%bash
for (( ; ; )); do
echo "This is a infinite loop!"
done1
2
3
4
5
%%bash
for dir in $(ls -d */); do
echo $dir
donef2.csv/
spark-warehouse/
break and continue¶
break, continue and exit work as in other programming languages.