LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2010, 02:44 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 569

Rep: Reputation: 84
What does -p do in #!/bin/bash -p


I don't have a problem but I do have solution that leads to a question.

I created a bash script which sets up paths and variables for some work I do. The header was a basic shebang, #!/bin/bash.

After running my script the environment was exhibiting strange behavior that basically was forcing me to run a command twice. The first invocation would cause an error and the second would work. I have no idea why.

The fix was to add -p to my shebang, #!/bin/bash -p. I tried the -p because I saw it used on some other scripts and not because I understand what it does.

By dumb luck it fixed my issue. commands in the setup work the first time.

I've done some googling trying to figure out what the -p option does but haven't found anything. Nor can I find it in a reference book I have - "Learning the bash shell".

If anyone knows what the -p option does I would love an explanation or a reference to the info.

Thanks to all.
 
Old 05-21-2010, 02:50 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
The command to find out what that does is:

Code:
core:~$ bash -c "help set"
and...

Code:
        -p  Turned on whenever the real and effective user ids do not match.
            Disables processing of the $ENV file and importing of shell
            functions.  Turning this option off causes the effective uid and
            gid to be set to the real uid and gid.
(Edit: clarification this has to do with setuid behavior if you want to research it further)

Last edited by rweaver; 05-21-2010 at 02:53 PM.
 
Old 05-21-2010, 02:52 PM   #3
fruttenboel
Member
 
Registered: Jul 2008
Location: Tilburg NL
Distribution: Slackware 14.2 ciurrent, kernel 3.18.11
Posts: 270

Rep: Reputation: 48
Quote:
Originally Posted by sharky View Post
I don't have a problem but I do have solution that leads to a question.

I've done some googling trying to figure out what the -p option does but haven't found anything. Nor can I find it in a reference book I have - "Learning the bash shell".

Thanks to all.
Well, you forgot the best book that's already on your computer... The man pages. I issued 'man bash' and then entered '/-p' to find
Quote:
If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS variable, if it appears in the environment, is ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.
Next time, first try 'man' or 'info'. These are the treasure chests of Linux.

Last edited by fruttenboel; 05-21-2010 at 02:53 PM.
 
Old 05-21-2010, 03:23 PM   #4
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
Quote:
Originally Posted by fruttenboel View Post
Well, you forgot the best book that's already on your computer... The man pages. I issued 'man bash' and then entered '/-p' to find


Next time, first try 'man' or 'info'. These are the treasure chests of Linux.
Our sysadmins, in their infinite wisdom, have setup the man pages to come up in a horrible gui. The gui has nothing but an exit button so there no way to search. Since this gui man has been implemented I almost never use man. The man page for bash is so long it's useless without a search capability. And with the way it's setup I can't pipe it to col -b to create a text file.

Thanks for the help. But now that I know what -p does it's even more confusing how it fixed my problem.

Oh well.
 
Old 05-21-2010, 04:00 PM   #5
fruttenboel
Member
 
Registered: Jul 2008
Location: Tilburg NL
Distribution: Slackware 14.2 ciurrent, kernel 3.18.11
Posts: 270

Rep: Reputation: 48
Quote:
Originally Posted by sharky View Post
Our sysadmins, in their infinite wisdom, have setup the man pages to come up in a horrible gui. The gui has nothing but an exit button so there no way to search. Since this gui man has been implemented I almost never use man. The man page for bash is so long it's useless without a search capability. And with the way it's setup I can't pipe it to col -b to create a text file.

Thanks for the help. But now that I know what -p does it's even more confusing how it fixed my problem.

Oh well.
Of course therre is a way to search and print it...

Just get the man page on screen and 'paint' the full text with the left mouse button. Then open an editor and paste the text into that buffer (middel mouse button). Repeat until everything is in. Then search (or print, or whatever).
 
Old 05-21-2010, 04:09 PM   #6
impert
Member
 
Registered: Feb 2009
Posts: 282

Rep: Reputation: 54
The linux.die.net site has man pages. But perhaps that's the "horrible gui" that you mentioned?
 
Old 05-21-2010, 04:56 PM   #7
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
You know, if you read "man less", you'd know that you can actually do very powerful searches. Don't blame the tools for being bad unless you actually know how to use them. Also, if you read "man man", you'd know that you can actually dump any manpage to a printable Postscript document.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] #!/bin/sh vs #!/bin/bash -- script executes differently; each way = different bugs GrapefruiTgirl Programming 21 12-16-2009 05:30 PM
Really strange problem - RedHat /bin/sh vs /bin/bash leeharris Programming 4 02-13-2009 06:35 AM
How to add paths to sbin, bin/bash, bin sh for users gopi.d Fedora 3 12-07-2007 12:47 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM
bin/bash:usr/bin/lpr NO SUCH FILE OR DIRECTORY Adibe_Hamm Linux - Newbie 3 10-14-2003 02:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration