Computing.Net > Forums > Unix > K-shell script argument

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

K-shell script argument

Reply to Message Icon

Name: pj_elia
Date: May 21, 2003 at 09:57:08 Pacific
OS: HPUX 11.0
CPU/Ram: 400/1000
Comment:

I need to do and IF statement that checks to see if a variable contains a particular value. ex. x=redcars. IF x contains "car" do whatever.

Thanks for the help. I've been trying to figure this out for awhile.

Paul




Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: May 21, 2003 at 11:30:48 Pacific
Reply:

x=redcars


if [ "$x" == "redcars" ]
then
echo do something
fi

this is how I'd do it. When using string variables, I put the quotes around the variable so that if it is empty, it won't error out.


0

Response Number 2
Name: David Perry
Date: May 21, 2003 at 12:29:20 Pacific
Reply:

if [ `echo $x | grep -c car` -gt 0 ] ; then

the above would check for the string car within the variable if you need to check substring.


0

Response Number 3
Name: pj_elia
Date: May 22, 2003 at 11:27:41 Pacific
Reply:

Thanks for the tips guys. I'll give it a try.


0

Response Number 4
Name: WilliamRobertson
Date: May 26, 2003 at 17:02:09 Pacific
Reply:

In Korn shell:

if [[ $x = *red* ]]
then ...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


typeset inside a function shell awk



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: K-shell script argument

Shell script to extract text www.computing.net/answers/unix/shell-script-to-extract-text/3999.html

korn shell script problem (using awk ? ) www.computing.net/answers/unix/korn-shell-script-problem-using-awk-/3547.html

C Shell script help! www.computing.net/answers/unix/c-shell-script-help/3108.html