| Various shell odds and ends |
expr $string : 'xxx\(.*\)' ## picks out stuff matched within ()
expr $string : '.*' ## length of string
It can also be used for arithmetic
VAR=`expr $VAR + 1` # increments VAR
although ksh's $(( )) is more convenient:
VAR=$(( VAR + 1 ))
STRING=$( echo $STRING )
USER=$( id | sed -e 's/.*(//' -e 's/).*//' )
ID=$( id | sed -e 's/uid=//' -e 's/(.*//' )
BOLD=`tput smso`
BOLDOFF=`tput rmso`
echo "This is ${BOLD}portable${BOLDOFF}."
eval "`awk -f program`" ## where awk program produces output like...
## VAR1=something
## VAR2=something_else
${PAGER:=more}
the colon :
signifies that the empty string is to be treated the
same as an unset string (in this case the default more
is assigned in either case).
#!/usr/bin/*sh not
#!/bin/*sh
Last update: 2000 December 10