i got a file called Pass1, and then i need to passed a number to my script with the '-p pass_mark' option.
Example type
Pass1 -p 18
to pass 18 to my script for comparing things, so how can i do it?
i got a file called Pass1, and then i need to passed a number to my script with the '-p pass_mark' option.
Example type
Pass1 -p 18
to pass 18 to my script for comparing things, so how can i do it?
If you want named parameters, check up on the getopts function (available in a ksh and bash near you)
If you only want to pass any parameter, they are automagically stored in $1 to $9 individually and $*/$@ collectively.
example:
whie getopts "p:" opt
do
case $opt in
p) pass_mark = $OPTARG ;;
esac
done
In your cass to pass , just the mark, you could just run the script as
scriptname 45
and then in your script, accept
pass_mark=$1
cheers,
Devaraj Takhellambam
shift $((OPTIND -1))
Thank you
i did somethings like that, but is not working
while getopts "p:" opt
do
case $opt in
p) pass_mark = $OPTARG ;;
esac
done
pass_mark=$1
if [ 50 -lt $1 ]
then
echo "50 is less than $1"
else
echo "50 is not less than $1"
fi
can i use other command in stead of getopts?
Yes you could just use a command line parameter.
In your script
pass=$1
if [ $pass -lt 50 ]; then
echo "Pass mark of $pass is less than 50"
else
echo "Pass mark of $pass is greater than 50"
fi
Run the script as
scriptname 45
cheers,
Devaraj Takhellambam
but if i have a default pass mark then what can i do? if people just run "scriptname" without anything after the scriptname, so what can i do for it??