ABLE has the ability to execute shell scripts. These are simple text files with commands in them. The shell commands in the file are executed in consecutive order as if they had been typed at the command line.
To be recognised, a script file must
start with a line #!sh
or
#!/bin/sh
. After this, commands may be placed
on each line as desired. Lines starting with a “#”
are interpreted as comments and are ignored.
Example 3.6. Example shell script
This is an example shell script which tests the test command and shell quoting.
#!/bin/sh # ABLE shell test echo "TEST: test" [ 1 -lt 2 ] && echo "1 < 2" [ 2 -lt 1 ] && echo "2 < 1" [ 2 -gt 1 ] && echo "2 > 1" [ 1 -gt 2 ] && echo "1 > 2" echo "TEST: simple variable expansion" foo=bar echo $foo echo "TEST: variable expansion within test" bar=10 [ 1 -lt $bar ] && echo "1 < $bar" [ 1 -gt $bar ] && echo "1 > $bar" echo $bar echo "TEST: quoting tests" echo TEST: single quotes echo '\\ \$ \w $bar $+ $foo \$foo' echo TEST: double quotes echo "\\ \$ \w $bar $+ $foo \$foo" echo TEST: no quotes echo \\ \$ \w $bar $+ $foo \$foo echo TEST: quoted single var echo "$foo$foo" echo TEST: quoted curly brace single var echo "${foo}${foo}" echo TEST: positional parameters echo There are $# positional parameters echo All parameters ">$*< after" echo Parameter 0,1,2 ">$0 $1 $2<" echo Parameter 0:$0 echo Parameter 1:$1 echo Parameter 2:$2 echo Parameter 3:$3
When executed, the above script should produce the following output.
>(tftpboot)test.sh one two three readudp: incorrect length TEST: test 1 < 2 2 > 1 TEST: simple variable expansion bar TEST: variable expansion within test 1 < 10 10 TEST: quoting tests TEST: single quotes \\ \$ \w $bar $+ $foo \$foo TEST: double quotes \ $ \w 10 $+ bar $foo TEST: no quotes \ $ w 10 $+ bar $foo TEST: quoted single var barbar TEST: quoted curly brace single var barbar TEST: positional parameters There are 4 positional parameters All parameters >one two three< after Parameter 0,1,2 >(tftpboot)test.sh one two< Parameter 0:(tftpboot)test.sh Parameter 1:one Parameter 2:two Parameter 3:three >