File tree Expand file tree Collapse file tree 9 files changed +21
-17
lines changed Expand file tree Collapse file tree 9 files changed +21
-17
lines changed Original file line number Diff line number Diff line change 33
33
34
34
- Print out a Bash array:
35
35
36
- ` echo ${array [@]} `
36
+ ` echo ${{{array_name [@]}} } `
Original file line number Diff line number Diff line change 13
13
14
14
- Allow matching multiple patterns:
15
15
16
- ` case {{$ANIMAL}} in {{cat}}) echo "It's a cat" ;;& {{cat|dog}}) echo "It's a cat or a dog" ;;& *) echo "Fallback" ;; esac `
16
+ ` case {{$ANIMAL}} in {{cat}}) {{ echo "It's a cat"}} ;;& {{cat|dog}}) {{ echo "It's a cat or a dog"}} ;;& *) {{ echo "Fallback"}} ;; esac `
17
17
18
18
- Continue to the next pattern's commands without checking the pattern:
19
19
20
- ` case {{$ANIMAL}} in {{cat}}) echo "It's a cat" ;& {{dog}}) echo "It's either a dog or cat fell through" ;& *) echo "Fallback" ;; esac `
20
+ ` case {{$ANIMAL}} in {{cat}}) echo {{ "It's a cat"}} ;& {{dog}}) {{ echo "It's either a dog or cat fell through"}} ;& *) {{ echo "Fallback"}} ;; esac `
21
21
22
22
- Display help:
23
23
Original file line number Diff line number Diff line change 5
5
6
6
- Skip to the next iteration:
7
7
8
- ` while :; do continue; echo "This will never be reached"; done `
8
+ ` while :; do continue; {{ echo "This will never be reached"}} ; done `
9
9
10
10
- Skip to the next iteration from within a nested loop:
11
11
12
- ` for i in {1..3}; do while :; do continue 2; done; done `
12
+ ` for i in {{{ 1..3}}} ; do {{echo $i}}; while :; do continue 2; done; done `
Original file line number Diff line number Diff line change 21
21
22
22
- Create a coprocess which repeatedly reads ` stdin ` and runs some commands on the input:
23
23
24
- ` coproc {{name}} { while read line; do {{command1; command2; ...}}; done } `
24
+ ` coproc {{name}} { while read {{ line}} ; do {{command1; command2; ...}}; done } `
25
25
26
26
- Create a coprocess which repeatedly reads ` stdin ` , runs a pipeline on the input, and writes the output to ` stdout ` :
27
27
28
- ` coproc {{name}} { while read line; do echo "$line" | {{command1 | command2 | ...}} | cat /dev/fd/0; done } `
28
+ ` coproc {{name}} { while read {{ line}} ; do {{ echo "$line"}} | {{command1 | command2 | ...}} | cat /dev/fd/0; done } `
29
29
30
30
- Create and use a coprocess running ` bc ` :
31
31
Original file line number Diff line number Diff line change 4
4
> This command does not support longform options and thus using ` getopt ` is recommended instead.
5
5
> More information: < https://www.gnu.org/software/bash/manual/bash.html#index-getopts > .
6
6
7
- - Check if an option is set:
7
+ - Check if an option is the first set option in the current context :
8
8
9
- ` getopts {{x}} {{opt}}; echo $opt `
9
+ ` getopts {{x}} {{opt}}; echo ${{ opt}} `
10
10
11
- - Set an option to require an argument and check said argument :
11
+ - Check if an option is set in a string (specified option must be the first element of the string) :
12
12
13
- ` getopts {{x}}: {{opt}}; echo $OPTARG `
13
+ ` getopts {{x}} {{opt}} "{{string text}}"; echo ${{opt}} `
14
+
15
+ - Set an option to require an argument and print them:
16
+
17
+ ` getopts {{x}}: {{opt}}; echo ${{opt}} $OPTARG `
14
18
15
19
- Check for multiple options:
16
20
17
- ` while getopts {{xyz}} {{opt}}; do case $opt in x) echo x is set;; y) echo y is set;; z) echo z is set;; esac; done `
21
+ ` while getopts {{xyz}} {{opt}}; do case ${{ opt}} in x) {{ echo x is set}} ;; y) {{ echo y is set}} ;; z) {{ echo z is set}} ;; esac; done `
18
22
19
23
- Set ` getopts ` to silent mode and handle option errors:
20
24
21
- ` while getopts :{{x:}} {{opt}}; do case $opt in x) ;; :) echo "Argument required";; ?) echo "Invalid argument" esac;; done `
25
+ ` while getopts :{{x:}} {{opt}}; do case ${{ opt}} in x) ;; :) {{ echo "Argument required"}} ;; ?) {{ echo "Invalid argument"}} esac;; done `
22
26
23
27
- Reset ` getopts ` :
24
28
Original file line number Diff line number Diff line change 17
17
18
18
- Create a menu from a Bash array:
19
19
20
- ` {{fruits}}=({{ apple orange pear banana}}) ; select {{word}} in ${{{fruits[@]}}}; do echo ${{word}}; done `
20
+ ` {{fruits}}={{( apple orange pear banana)}} ; select {{word}} in ${{{fruits[@]}}}; do echo ${{word}}; done `
Original file line number Diff line number Diff line change 9
9
10
10
- Continue from suspension if ` suspend ` was used in a non-nested shell (run this in a separate terminal):
11
11
12
- ` pkill -CONT bash `
12
+ ` pkill -CONT {{ bash}} `
13
13
14
14
- Force suspension even if this would lock you out of the system:
15
15
Original file line number Diff line number Diff line change 18
18
19
19
- Set max per-user process limit:
20
20
21
- ` ulimit -u 30 `
21
+ ` ulimit -u {{30}} `
22
22
23
23
- Display help (Bash only):
24
24
Original file line number Diff line number Diff line change 5
5
6
6
- Read ` stdin ` and perform an action on every line:
7
7
8
- ` while read line; do echo "$line"; done `
8
+ ` while read line; do {{ echo "$line"}} ; done `
9
9
10
10
- Execute a command forever once every second:
11
11
You can’t perform that action at this time.
0 commit comments