LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-14-2014, 09:38 PM   #1
paul_e_t
Member
 
Registered: Sep 2003
Location: Orlinda TN USA
Distribution: SuSE 8.2, 9.0,.1,.2,.3,W98, Win ME, XP, Centos 4.2,4.3, VM DSL3.3 appliance
Posts: 125

Rep: Reputation: 17
PS1 prompt way to long


pault@pault-HP-Pavilion-g7-Notebook-PC

My prompt given in dot profile (?) is way to long. Not only that but it does not have a dot in front to make the file hidden??. All I want is my login name "pault" as a prompt however I can't properly read or understand the complex script. I also cannot find any references. running Mint17 I sure could use help. please

cat profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

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

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi

Last edited by paul_e_t; 08-14-2014 at 09:47 PM.
 
Old 08-14-2014, 10:48 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,898

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
Bash Prompt Howto
 
1 members found this post helpful.
Old 08-14-2014, 10:50 PM   #3
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 517
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
Put in ~/.bashrc
Code:
PS1=whatever
Mine is PS1="dj@\h:\W$ "
 
Old 08-15-2014, 02:42 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
Quote:
Originally Posted by paul_e_t View Post
pault@pault-HP-Pavilion-g7-Notebook-PC

My prompt given in dot profile (?) is way to long. Not only that but it does not have a dot in front to make the file hidden??. All I want is my login name "pault" as a prompt however I can't properly read or understand the complex script. I also cannot find any references. running Mint17 I sure could use help. please
Things are easier to read when you put programs/scripts in code blocks to preserve indentation. I'll put some indentation while explaining..

Code:
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
This tests for the existence of the PS1 environment variable. If it is missing then the convention is that the shell is being used to run a script, so you don't need the prompt string anyway. This just saves time...
Code:
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
This checks for the type of shell. /bin/sh is a shell, but doesn't necessarily have all the features of bash. The first part is just testing to see if the environment variable BASH has a non empty value, then it checks to see if the value is "/bin/sh". If it is not, then the true part of the test is processed (it assumes you are using bash, which is reasonable in this context. If you were running the C shell- csh - it would be processing a different file than this one anyway).
Code:
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
All this is doing is checking for the existence of the file /etc/bash.bashrc. If the file exists, then the script includes the command from that file.

If the line "#PS1='\h:\w\$ '" weren't commented out, it would set the users command prompt to the host name, and the current working directory. It just provides a simple way to remind the user of what host (the \h), and directory (the \w) the command the user is about to type in will affect. If there is only one machine, then the "\h: can be left out. If none of this is desired, then I would suggest using "PS1='$ '" instead.

The ". /etc/bash.basrc" just adds the contents of the file to the command stream already being executed. This allows environment variables that may be defined in that file to be added to the current process environment. It works exactly as if the contents of the file were in this file (the /etc/profile I'm annotating)
Code:
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
This is the part executed if the shell is identified as /bin/sh as determined by the testing of the BASH environment variable. The syntax used is the more restricted syntax of the bourne shell, and is simplified. The "`id -u`" identifies the user id (see the manpage for the id command), and checks to see if the value is 0. If it is 0, then the login is for the root user, and sets the command prompt to '# '. This allows a relatively easy visual identification/reminder that the root account (with the power to destroy things accidentally) is being used. If the user id is not 0, then the prompt is set to '$ ', indicating the the login is a bit safer to use (damage is limited to only the files/processes that the login can access).
Code:
fi

# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
This last part is a bit more complex. This part looks for the existance of a directory (named /etc/profile.d). If the directory exists, then the "for i" loop will loop for each file in /etc/profile.d that has the extension ".sh", and include the commands in the identified file as part of the profile. This is used to define some specialty environment variables that may be needed by users. The files may define an application environment with a different command search list, additional default libraries, or other setup needed for the given login. These files are sometimes added to the /etc/profile.d directory by things like database systems, work processing systems,... anything that needs a special setup to work. They COULD have been done as part of the application startup (see google earth for a rather lengthy setup), but are done here to save time later. If the environment can be setup once for the user, why do it each time the application is used?

Hope this helps.

Last edited by jpollard; 08-15-2014 at 02:48 AM.
 
1 members found this post helpful.
Old 08-15-2014, 06:49 AM   #5
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
Have you checked "hostname"?
 
Old 08-15-2014, 06:51 AM   #6
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
The "@somename" is usually hostname.
 
1 members found this post helpful.
Old 08-15-2014, 10:58 AM   #7
paul_e_t
Member
 
Registered: Sep 2003
Location: Orlinda TN USA
Distribution: SuSE 8.2, 9.0,.1,.2,.3,W98, Win ME, XP, Centos 4.2,4.3, VM DSL3.3 appliance
Posts: 125

Original Poster
Rep: Reputation: 17
Tried DJ Shaji's suggestion but ran into another problem without any home symbol key on this keyboard so I cy and pasted:
cat ~/.bashrc and cat ~/\.bashrc
both results
cat: /home/pault/.bashrc: No such file or directory

cannot get DJ's suggestion to work.
found the .profile here is a copy and reason no .bashrc file.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi


I am afraid to touch the long complex script so i'll have to leave as is.

Many thanks to Jpollard for his excelllent analysis.
 
Old 08-15-2014, 11:13 AM   #8
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
To just get "user $ " as your prompt, from your home directory run
Code:
echo "PS1='\u \$ '" >> .bashrc
I like to have my prompt display the host and full path to be sure of where I'm running a command, so use
Code:
PS1='\u@\h \w \$ '
 
Old 08-15-2014, 01:25 PM   #9
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
Just check & possibly edit hostname
 
Old 08-16-2014, 11:28 AM   #10
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 517
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
If there's no ~/.bashrc just create it e.g. like this:
Code:
touch ~/.bashrc
Any redirection from the shell to the file will create it automatically, as another user pointed out above.
 
  


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
Please explain..decode? my (long!) PS1 prompt string. GTrax Linux - General 4 05-27-2013 07:48 PM
ssh to server - PS1 prompt does not complete Harry Ronis Linux - Server 5 04-17-2012 03:19 PM
[SOLVED] Ksh93 vs. Pdksh88: Custom PS1 prompt not working kristo5747 Linux - Newbie 1 01-19-2011 12:55 PM
Post your BASH prompt [PS1]? introuble General 11 12-27-2006 04:47 PM
$PS1 different in X and prompt codec Slackware 7 06-27-2004 05:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:21 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration