LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Is this code? (https://www.linuxquestions.org/questions/programming-9/is-this-code-4175578736/)

bluesclues227 05-01-2016 02:52 AM

Is this code?
 
Hello I'm trying to understand what I'm looking at here as I'm a complete programming newbie.. OK this is the output of more /etc/profile:

[code]if [ "$PS1" then
if ["$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "'id -u'" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
[\code]

If anyone knows what language this is please let me know, thanks in advance!

grail 05-01-2016 04:26 AM

Yes it is a shell script, it sets up your environment.

In future, please use [code][/code] tags around code to keep formatting :)

X-LFS-2010 05-02-2016 12:57 PM

correction:

if [ "$PS1" ] ; then

-----------------------
it is part of a /etc/profile or $HOME/.profile

it is checking if variable PS1 is set (has a non-empty value)

PS1 is the IBM AIX term for "prompt statement, level 1" which looks like this:

$ echo "hi"
hi

"$" == PS1. if you entered PS2 "subshell", PS2 is usually ">"

"$" is only printed if the "shell session" is interactive

it tells you "where you are"

---------------------------------
the script above "sources" (runs) a different script if it detects BASH, else sets PS1 according to which user is opening a terminal/bash session

very typical hacks added to /etc/profile

be VERY CAREFUL hacking /etc/profile: any noise emitted by echo(1) or due to error will cause logins to FAIL. and will cause programs like rsync rsh or something which expect no output and use output as commands (they expect they are not in interactive mode): to fail miserably.

dont hack /etc/profile, use the minimalistic default, unless your sure of what your dealing with

jpollard 05-06-2016 12:59 PM

It isn't limited to just IBM. ALL UNIX and unix like systems use PS1 and PS2 for prompt string (PS1 for the first prompt, PS2 for any continuations...)

bluesclues227 05-08-2016 09:28 PM

Thanks you all!


All times are GMT -5. The time now is 01:21 AM.