Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 26th, 2003, 04:13 PM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
Bash script

1) #!/bin/bash -p
What is -p means ?

2) killall dhcpcd > dev/null 2 > & 1
What is 2 > & 1 means ?

3) if [ $? -ne 0 ]
then
ifconfig eth0 up;
exit 1;
fi
What is "$?" ? Does it refer to the last variable reference ?

4) suid putdata update &&
What is && means ?

I did look at the web site that gives instruction on BASH programming, but some of the things mentioned above was not covered.

Reply With Quote
  #2  
Old June 26th, 2003, 05:20 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,833 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 4 h 11 m 7 sec
Reputation Power: 446
Re: Bash script

Quote:
Originally posted by linh
1) #!/bin/bash -p
What is -p means ?

I checked the man page on that and did not find that option. I did find a --posix option that might be equivalent.

You should do a web search on bash and -p to see what you can find. If the archaic K&R syntax in your other post is any indication, this -p option might also be archaic.

Quote:

2) killall dhcpcd > dev/null 2 > & 1
What is 2 > & 1 means ?

It means to redirect stderr to the same place you redirected stdout. That's a real handy notation that I wish worked in DOS.

Quote:

3) if [ $? -ne 0 ]
then
ifconfig eth0 up;
exit 1;
fi
What is "$?" ? Does it refer to the last variable reference ?

That's a predefined special environment variable, which in this case is the exit code of the previous command/process. So this statement says that if the previous command failed (0 means it ran successfully), then bring the ethernet interface back up and exit with a non-zero exit code to indicate failure. BTW, that is why your C programs should always return an int: zero if successful (using return 0; ) and non-zero if an error was encountered (using something like exit(1) ).

There's an entire set of these special variables; eg:
$$ == the current process id
$? == the exit code of the previous process
$# == the number of parameters passed to this process; just like argc
$* == the argument list -- there are two different variables for this that handle quoting differently, so you'd better research this one.

perl uses many of the same special variables, plus many more.

Quote:

4) suid putdata update &&
What is && means ?

This one I'm not at all sure. You'd better do a web search on suid and "&&". Are you sure that it's "&&" and not "$$"?

Last edited by dwise1_aol : June 26th, 2003 at 05:24 PM.

Reply With Quote
  #3  
Old June 26th, 2003, 06:25 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 6 m 2 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
&& is a logical AND and is often used to decouple, or serialise commands at the bash promt, as in

# ./configure && make

ie if the first process (left hand side of &&) fails, then the system won't evaulate the right hand side of the expression.

This all implies that there could be a missing command on the end of this last example...

just a thought


christo

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Bash script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway