1832988 Members
2921 Online
110048 Solutions
New Discussion

input parameter

 
SOLVED
Go to solution
andi_1
Frequent Advisor

input parameter

Hi,

My script needs the following capability. It either gets no parameters or one parameter called expert.

myScript.sh
or
myScript.sh expert

Does anyone know how can I find if expert was passed in?

Thank you.
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: input parameter

Hi:

Yes, that is rather easy:

MYPARAM=""
if [ $# -ge 1 ]
then
MYPRAM=$1
shift
fi

if [ -n "${PARAM}" ]
then
echo "I have a value"
else
echo "I don't"
fi
If it ain't broke, I can fix that.
andi_1
Frequent Advisor

Re: input parameter

Hi Clay,

Thanks for the response.

Can you tell me how can I check if expert was actually specified?

if [ "$MYPARAM"=="expert" ]; then
fi

doesn't seem to work.

Thanks again!
A. Clay Stephenson
Acclaimed Contributor

Re: input parameter

Hi again:

Pardon my inconsistant varaibable naming; all of the above should have been 'MYPARAM' but the answer to your question is to change '==' to '=' and you are set.
If it ain't broke, I can fix that.