Computing.Net > Forums > Unix > Script help, Im having a brain fart

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.

Script help, Im having a brain fart

Reply to Message Icon

Name: aka
Date: May 15, 2007 at 11:52:09 Pacific
OS: AIX
CPU/Ram: P4 / 255
Product: Custom
Comment:

Hi all,

This is a simple script for some other I’m doing, but before change example1 I wanted to test with an example 2.

The code must be work this way.

./test James
Good morning James--- END

./test nojames
Usage: ./test James or james.

Code I have done, but Im having a hard brain fart, is this.

#!/bin/bash
name=$1

if ($name != “James” -o $name != “james” ); then
echo "usage: $0 James or james"
exit 1
else

echo "Good morning $name"

fi


Don´t freak out until you know the facts...Relax...!



Sponsored Link
Ads by Google

Response Number 1
Name: Guy
Date: May 15, 2007 at 17:57:20 Pacific
Reply:

Try [] instead of ().

Try -a instead of -o.



0

Response Number 2
Name: aka
Date: May 15, 2007 at 18:02:09 Pacific
Reply:


I already did that before, but didnt help, some other clue ?

Thanks.

Don´t freak out until you know the facts...Relax...!


0

Response Number 3
Name: Guy
Date: May 15, 2007 at 18:11:04 Pacific
Reply:

Also make sure that:

there is a space/blank right after [

there is a space/blank right before ]

What happens?


0

Response Number 4
Name: aka
Date: May 15, 2007 at 18:19:03 Pacific
Reply:

Great, it worked.

But, what does -a do ?... why didnt it work with -o, I had made some other codes with -o and it work ?..

Thanks Guy...

Don´t freak out until you know the facts...Relax...!


0

Response Number 5
Name: nails
Date: May 16, 2007 at 09:31:35 Pacific
Reply:

Are you familiar with boolean algebra? In shell the -a is the "and" and the -o is "or".

($name != “James” -o $name != “james”

The above reads if name is NOT James or name is NOT james, it is true. If you stop to think about it, with an "or" either [Jj]ames is still true.

Check out this link:
http://en.wikipedia.org/wiki/Boolea...

click on "AND" for further info.

If you stil have trouble, try something like this:

# untested
if [ $name = "James" -o $name = "james" ]
then
:
else
echo "name is not [Jj]ames"
fi


0

Related Posts

See More



Response Number 6
Name: aka
Date: May 16, 2007 at 09:35:32 Pacific
Reply:


thanks Nails.

I already got some torrents for O'Reilly bash scripting.

and found some interesting links, including yours, but it will always be helpfull to post here ;)

Don´t freak out until you know the facts...Relax...!


0

Sponsored Link
Ads by Google
Reply to Message Icon

To Extract information fr... Help with 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: Script help, Im having a brain fart

Shell script help www.computing.net/answers/unix/shell-script-help/7043.html

force the script to exit w/0 www.computing.net/answers/unix/force-the-script-to-exit-w0-/4303.html

Shell Script: Get value from a file www.computing.net/answers/unix/shell-script-get-value-from-a-file/5760.html