Skip to content

Instantly share code, notes, and snippets.

@ykst
Created October 9, 2012 18:53
Show Gist options
  • Save ykst/3860689 to your computer and use it in GitHub Desktop.
Save ykst/3860689 to your computer and use it in GitHub Desktop.
sh syntax memorandom
#!/bin/sh
MY_NAME=$0;
BASE_NAME=${0##*/};
DIR_NAME=${0%/*};
DIRDIR_NAME=${0%/*/*};
DEF_NAME=${_HIDDEN_NAME:-default}
echo $BASE_NAME;
echo $DIR_NAME;
echo $DIRDIR_NAME;
echo $DEF_NAME;
echo pid = $$
LVAL=1;
RVAL=2;
func()
{
echo list is $*
for x in $*; do
echo param $x;
done
echo quated is $@
for x in $@ ; do
echo quated param $x;
done
return 10;
}
#for shs in `find . `; do
# echo $shs;
#done
if [ -e $0 -a $2 -le $3 ]; then
echo hello
elif [ -r $BASE_NAME ]; then
echo readable
fi
if [ -d $DIR_NAME ]; then
echo $DIR_NAME is directory;
fi
if [ -f $BASE_NAME ]; then
echo $BASE_NAME is file;
fi
if [ ! -x $BASE_NAME ]; then
echo $BASE_NAME is not executable;
fi
if [ -w $BASE_NAME ]; then
echo $BASE_NAME is writable;
fi
case $1 in
hello)
func casehello;
;;
foobar)
func casefoobar;
;;
foo|bar)
func case foo or "bar";
;;
*)
func casedefault;
;;
esac
echo func result = $?
TESTVAL=0
while [ $TESTVAL -lt 10 ]; do
TESTVAL=$((TESTVAL + 1));
echo $TESTVAL;
done
for_each_cliche()
{
# get configuration path at the first operand and use the rest as a command and options
conf=$1; shift;
# ignore comment lines and use line buffer to read up each set up
egrep -v '^#' $conf |
while read name edev eoff ecnt wdev wskip wopt; do
# $@ contains commands, and given parameters give full set of operation
"$@" $name $edev $eoff $ecnt $wdev $wskip $wopt || fatal_err;
done
}
echo "type name>"
read name;
echo "name is $name"
echo waiting for SIGINT
trap 'echo trapped SIGINT' 2
sleep 10
@ykst
Copy link
Author

ykst commented Oct 9, 2012

to keep me remind bourne shell syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment