% people="jack and jill *"
% print "$people"
jack and jill *
% print $people
jack and jill file1 file2 file3
% print '$people'
$people
% print \$people
$people
var=100 makes var the string '100'.
integer var=100 makes var the integer 100.
$(( expression )) to return the value of
expression, or (( expression )) to return only an exit
status (true or false).
% integer x=1
% (( y=x*10 ))
% (( x+=1 ))
% print $x $y
2 10
$(( expression )) and (( expression
)) you can use parentheses for grouping, the arithmetic operators
+, -, *, /, %, <<, >>, &, |, ~, ^, and the relational
operators <, >, <=, >=, ==, !=, &&, and ||.
$ set -A people Jack and Jill
$ set -A others ${people[*]} and Jane and John
$ others[7]=and ; others[8]=Joseph
${#variable[*]}.
$ print ${#others[*]}
9
$variable refers to ${variable[0]}.
$ print ${#others} ${#others[*]}
4 9
$ print $people
Jack
$ print ${people[1]}
and
$ print ${others[$(( ${#others[*]} - 1 ))]}
Joseph
$* (a space
separated list) and $@ (a list with each argument double
quoted separately). Individual arguments to the shell script are
referenced as $1, $2, $3, etc., and $0 is the
name of the shell script itself.
$# indicates how many arguments were passed.
#!/usr/local/bin/ksh
integer i=1
for arg in $@
do
print "Argument $i is '$arg'."
(( i+=1 ))
done
return 0
-n string |
string not null? |
-z string |
string null? |
-a filename |
exists? |
-f filename |
is plain file? |
-d filename |
is directory? |
-s filename |
exists and not empty? |
-r filename |
read permission? |
-w filename |
write permission? |
-x filename |
execute permission? |
-O filename |
your file? |
-G filename |
your group? |
file1 -nt file2 |
file1 newer than file2? |
file1 -ot file2 |
file1 older than file2? |
if [[ ! -f output.file ]]; then
print "output.file does not exist."
fi
$(command) is literally replaced by the output from
command (the Bourne shell syntax for this was graves:
`command`).
$ set -A today $(date)
$ print ${today[*]}
Mon Oct 20 07:31:58 EDT 1997
$ print ${#today[*]}
6
$ print "${today[1]} ${today[2]}, ${today[5]}"
Oct 20, 1997