2013-08-22 03:34:11 +02:00
|
|
|
# To implement a for loop:
|
2014-08-08 19:52:43 +02:00
|
|
|
for file in *;
|
2013-09-01 21:40:10 +02:00
|
|
|
do
|
|
|
|
echo $file found;
|
2013-08-11 21:37:11 +02:00
|
|
|
done
|
2013-08-12 04:09:29 +02:00
|
|
|
|
2013-08-22 03:34:11 +02:00
|
|
|
# To implement a case command:
|
2013-08-12 04:09:29 +02:00
|
|
|
case "$1"
|
|
|
|
in
|
|
|
|
0) echo "zero found";;
|
|
|
|
1) echo "one found";;
|
|
|
|
2) echo "two found";;
|
2013-11-03 20:26:56 +01:00
|
|
|
3*) echo "something beginning with 3 found";;
|
2013-08-12 04:09:29 +02:00
|
|
|
esac
|
2014-08-13 19:49:56 +02:00
|
|
|
|
|
|
|
# Turn on debugging:
|
|
|
|
set -x
|
|
|
|
|
|
|
|
# Turn off debugging:
|
|
|
|
set +x
|
2015-09-04 10:16:54 +02:00
|
|
|
|
|
|
|
# Retrieve N-th piped command exit status
|
|
|
|
printf 'foo' | fgrep 'foo' | sed 's/foo/bar/'
|
|
|
|
echo ${PIPESTATUS[0]} # replace 0 with N
|
2015-09-04 11:09:39 +02:00
|
|
|
|
|
|
|
# Lock file:
|
|
|
|
( set -o noclobber; echo > my.lock ) || echo 'Failed to create lock file'
|