forked from qinshulei/ubuntu-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash
66 lines (53 loc) · 897 Bytes
/
bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# To implement a for loop:
for file in *; do
echo $file found;
done
# while loop
while [ expression ]; do
commands
done
# if statement
if [expr]; then
commands
elif
commands
else
command
fi
# To implement a case command:
case "$1"
in
0) echo "zero found";;
1) echo "one found";;
2) echo "two found";;
3*) echo "something beginning with 3 found";;
esac
# functions
fname(){
commands
}
# Turn on/off debugging:
set -x
set +x
# Turn on/off fail exit:
set -e
set +e
# Turn on/off pip fail:
set -o pipefail
set +o pipefail
# How all bash scripts should start (sharp-bang)
#!/bin/bash
# <<< redirect words to stdin:
less <<< "foo bar"
# ctrl-x ctrl-e opens editor to work on long complex command
# split with space
IFS=" "
for LINE in `cat /etc/passwd`
do
echo $LINE
done
# read line
while read LINE
do
echo $LINE
done < /etc/passwd