LinuxQuestions.org
Review your favorite Linux distribution.
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-01-2016, 02:52 AM   #1
bluesclues227
LQ Newbie
 
Registered: Apr 2016
Posts: 25

Rep: Reputation: Disabled
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!

Last edited by bluesclues227; 05-08-2016 at 09:27 PM.
 
Old 05-01-2016, 04:26 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Yes it is a shell script, it sets up your environment.

In future, please use [code][/code] tags around code to keep formatting
 
Old 05-02-2016, 12:57 PM   #3
X-LFS-2010
Member
 
Registered: Apr 2016
Posts: 510

Rep: Reputation: 58
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

Last edited by X-LFS-2010; 05-02-2016 at 12:58 PM.
 
Old 05-06-2016, 12:59 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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...)
 
1 members found this post helpful.
Old 05-08-2016, 09:28 PM   #5
bluesclues227
LQ Newbie
 
Registered: Apr 2016
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks you all!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Coverity Report Finds Open Source Code Quality Beats Commercial Code jeremy Linux - News 0 07-30-2015 12:46 PM
100's of files infected by the same hacker code - any way to mass replace bad code? SirTristan Linux - Newbie 11 06-24-2012 08:08 AM
[SOLVED] Small matlab code to convert Morse code to plaintext using regular expressions gregorian Programming 3 03-31-2010 12:34 PM
small syntax problem with C code (implemented in Code Composer Studio) illiniguy3043 Programming 6 01-07-2008 02:14 AM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM

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

All times are GMT -5. The time now is 01:59 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