> >I have a situation where I need to check the positional parameter, if it is
> >equal to "-display" then I have to assign the next positional parameter to
> >my variable DISPLAY. For this I am running the following script but I am
> >unable to do it. Please help me in solving my problem.
> >i=0
> >for i in $*
> >do
> > if [ $i = "-display" ]
> > then
> > shift 1
> > DISPLAY=$i
> > fi
> > break
> >done
> >The script will be run like this:
> >$sh abcd.sh abc def -display 166.2.3.45:0 xyz
> There are probably a lot of ways to do that. Here is one.
> #!/bin/sh
> flag=0
> for i in $*
> do
> if [ "$i" = "-display" ]
> then
> flag=1
> elif [ $flag -ne 0 ]
> then
> flag=0
> DISPLAY=$i
> fi
> done
> echo $DISPLAY
I corrected my script accordingly, its working fine.
Is there any function/command in shell, similar to the getenv() function in C?
I want to check whether the DISPLAY environment variable is existing or not.
I can check like giving as below. But, is there any other optimal way?
if [ DISPLAY != "" ]
echo DISPLAY defined
else
echo DISPLAY not defined.
fi
Thanks.