LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 06-06-2010, 11:10 AM   #1
sombragris
Member
 
Registered: Jul 2004
Location: Asuncion, Paraguay, South America
Distribution: Slackware
Posts: 92

Rep: Reputation: 17
How to read $PS1 on non-login shells?


Maybe the answer is just too elementary, but I'm at a loss about how can I achieve this.

Let's say that I have a customized Bash prompt stored as a PS1 variable. My variable gets read every time I invoke a login shell, i.e., when logging in in one of the standard virtual terminal or by invoking xterm with the -ls parameter.

However, when I just invoke the terminal without specifying that it is a login shell, I just get something like: bash-XXX$ as a prompt.

My question is: where should I place my PS1 variable so that it could get read even on non-login shells?

Thanks in advance!
 
Old 06-06-2010, 11:35 AM   #2
xflow7
Member
 
Registered: May 2004
Distribution: Slackware
Posts: 157

Rep: Reputation: 20
I'm not positive, but I think you want to put the definition in ~/.bashrc which I believe gets executed for any interactive shell (login or not).

Dave
 
1 members found this post helpful.
Old 06-06-2010, 11:40 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Read the "man bash" section on invocation for which start-up files are read by default. Note that there may differences between distributions on this matter.

Also, be aware that any start-up file (or other script) can include lines that source other files. Any line of the pattern "source filename" or ". filename" means that the contents of that other file will be inserted at that point when the script is executed.
 
1 members found this post helpful.
Old 06-06-2010, 03:22 PM   #4
sombragris
Member
 
Registered: Jul 2004
Location: Asuncion, Paraguay, South America
Distribution: Slackware
Posts: 92

Original Poster
Rep: Reputation: 17
Thank you! It seems that setting $PS1 on .bashrc does the trick. So far, it's working. Thanks!!!
 
Old 06-06-2010, 06:21 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 10,886
Blog Entries: 1

Rep: Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307
Hi,

You could setup a .bashrc & .bash_profile for your user;
Code:
 sample .bash_profile;
 
 ~$ cat .bash_profile
 # .bash_profile
 #08-30-06 12:21
 #
 # Source .bashrc
 if [ -f ~/.bashrc ]; then
         . ~/.bashrc
 fi
Code:
 sample .bashrc;
 :~$ cat .bashrc
 
 #.bashrc
 #08-30-06 12:20 
 
 # Add bin to path
 
 export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"
 
 #export PATH="$PATH:$HOME/bin"
 
 # Dynamic resizing
 shopt -s checkwinsize
 
 # Custom prompt
 #PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 
 #08-29-06 11:40
 
 if [ `id -un` = root ]; then
    PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
  else
    PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
 fi
 
 #
 # Add color
 eval `dircolors -b`
 
 # User defined aliases
 alias cls='clear'
 alias clls='clear; ls'
 alias ll='ls -l'
 alias lsa='ls -A'
 alias lsg='ls | grep'
 alias lsp='ls -1 /var/log/packages/ > package-list'
 alias na='nano'
 alias web='links -g -download-dir ~/ www.google.com'
 
 #08-29-06 11:50
 
 #To clean up and cover your tracks once you log off
 #Depending on your version of BASH, you might have to use
 # the other form of this command
    trap "rm -f ~$LOGNAME/.bash_history" 0
 
 #The older KSH-style form
 #   trap 0 rm -f ~$LOGNAME/.bash_history
The .bashrc is very useful!

Last edited by onebuck; 06-07-2010 at 01:08 PM. Reason: correct vbcode block
 
1 members found this post helpful.
Old 06-07-2010, 12:26 PM   #6
sombragris
Member
 
Registered: Jul 2004
Location: Asuncion, Paraguay, South America
Distribution: Slackware
Posts: 92

Original Poster
Rep: Reputation: 17
Gary, thanks for the info. This is great!
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Login and Interactive shells Josh000 Slackware 7 04-23-2010 09:02 AM
Login shells / Non-login shells tofee Linux - Newbie 1 03-24-2006 11:03 PM
Chainging the PATH on login shells cliff76 Debian 5 06-16-2005 03:52 PM
Bash and login shells Adrohak Linux - Software 3 11-18-2004 10:21 AM
Login shells vs non-login shells lsmith Linux - General 2 03-31-2004 07:29 PM


All times are GMT -5. The time now is 01:51 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration