Script 26: Get Options 1
#!/bin/bash
args=`getopt abc: $*`
if test $? != 0
then
echo 'Usage: -a -b -c file'
exit 1
fi
then
echo 'Usage: -a -b -c file'
exit 1
fi
set -- $args
for i
do
case "$i" in
-c) shift;echo "flag c set to $1";shift;;
-a) shift;echo "flag a set";;
-b) shift;echo "flag b set";;
esac
do
case "$i" in
-c) shift;echo "flag c set to $1";shift;;
-a) shift;echo "flag a set";;
-b) shift;echo "flag b set";;
esac
done
Script 27: Get Options 2
#!/bin/bash
while getopts "ab:" flag
do
while getopts "ab:" flag
do
echo "$flag"
$OPTIND $OPTARG
done
done
Script 28: If Statement 1
#!/bin/bash -x
if [ -f $1 ]
then
echo "it is a ordinary file"
fi
Script 29: If Statement 2
if [ -f $1 ]
then
echo "it is a ordinary file"
fi
Script 29: If Statement 2
#!/bin/bash
if [ $(id -u) = "0" ]; then
echo "you are not logged in as a root"
fi
if [ $(id -u) = "0" ]; then
echo "you are not logged in as a root"
fi
Script 30: If Statement 3
#!/bin/bash
echo "enter dob"
read birthday
today=`date -I`
if test "$birthday" = "$today"
then
echo "hello happy birthday"
else
echo
echo "sorry to dissappoint you"
fi
echo "enter dob"
read birthday
today=`date -I`
if test "$birthday" = "$today"
then
echo "hello happy birthday"
else
echo
echo "sorry to dissappoint you"
fi
No comments :
Post a Comment