Bash basic instruuction.
Special variables
$#
, length of parameters, like len(sys.argv[1:])
in Python
$0
, $1
…, like sys.argv[0]
, sys.argv[1]
, … in Python
$*
, all parameters string. Like "$0 $1 ..."
$@
, all parameters list. Like "$0", "$1", ...
For loop
for i in 1 2 3 4 5
do
echo "Number $i"
done
for name in Alice Bob Charlie
do
echo "Hello, $name"
done
names=("Alice" "Bob" "Charlie")
for name in "${names[@]}"
do
echo "Hello, $name"
done
for (( i=0; i<5; i++ ))
do
echo "Number $i"
done
for file in /path/to/directory/*
do
echo "Processing $file"
done
for file in $(ls /path/to/directory)
do
echo "Found file $file"
done