Jump to content

Command line prompt


Recommended Posts

Also check that your login shell is bash and not sh (that is also commented in one of the above threads)

Sorry, but I was in a hurry when I typed the above post. You deserve a deeper explanation ;)

 

Check that your user's shell is bash and not sh.

 

~$ awk -F':' "/$USER/{print $NF}" /etc/passwd

/bin/bash

 

In case of being sh your user shell, when you open an xterm, the sh session started wont look into any configuration file as it is not a login shell (only login shells (bash or sh) look into /etc/profile, BUT only bash non login shell reads .bashrc), thus you'll get the default prompt instead of the one you expected. But if you open a login shell (through vc#), or as how paul stated you run xterm -ls, then sh will source /etc/profile and ~/.profile if it exists. That could be the reason of why new xterm don't show the prompt unless you source /etc/profile by hand.

 

HTH

Link to comment
Share on other sites

I finally just put a new line in ~/bashrc

PS1="[33[1;37m]u@[33[1;32m]h [33[1;37m]W[33[1;37m]#"

 

It does what I want!! :wink:

Link to comment
Share on other sites

  • 3 weeks later...

As garu points out the difference between a login shell and a non-login shell.

Do I detect a misunderstanding of the two?

 

This is what I understand and I'm sure aru will correct me if wrong :D

 

Simply: If you

su <username> its not a login shell, it belongs to the previous shell

su - <username> reexecutes the login scripts.

 

Its common practice not to put certain things into non login shells but into login shells. The rational being you might want to inherit from a previous one.

 

For instance su : will not change your path, i.e. not include /sbin if you want a root environment then you su -

 

Also changing shells is not a login shell. .e. you are in a ksh shell and want to go to bash. typing bash will not run the login scripts.

Link to comment
Share on other sites

This is what I understand and I'm sure aru will correct me if wrong  :D 

sure :P

...but not in this post as you are 100% right :D

 

Simply:  If you 

su <username>  its not a login shell, it belongs to the previous shell

True, that shell (ie "su" to become root) inherits all the environmet from the previous shell, included $USER. But as a non login shell, it reads and executes root's /root/.bashrc , so whatever you put in there you'll have available for the "su" session (ie a root's only PATH or a particular PS1)

 

su - <username> reexecutes the login scripts. 

Right, when you run "su -" all the login scripts are sourced, so the environment of that shell is completely the roots one (ie $USER becomes 'root')

 

Its common practice not to put certain things into non login shells but into login shells.  The rational being you might want to inherit from a previous one. 

What people use to do is to source .bashrc from .bash_profile, so in a login shell will be sourced .bash_profile (and hence .bashrc); and in a non login shell only .bashrc will be sourced (but the environment variables will be inherited from the parent shell). Thus yielding both non-login and login shells behave the same under user's eyes.

 

For instance su :  will not change your path, i.e. not include /sbin if you want a root environment then you su -

Right

 

Also changing shells is not a login shell.  .e. you are in a ksh shell and want to go to bash.  typing bash will not run the login scripts.

True, unless you don't explicit make it a login shell (ie bash --login)

 

;)

Link to comment
Share on other sites

Hey, I must have managed no typo's this time....

No corrections ... :D

 

It amazes me (coming from a unix backgound) to see friends (coming from a Windows background) but very competent in Linux struggling with these concepts. Small things like backgrounding a stopped job

 

ctrl +z then

bg

or backgrounding it to start

<command> &

 

Along with things like trying to use Samba when NFS is so much easier...

 

or not understanding an xhost + or setting DISPLAY envvar's.

 

(I have a specific friend in mind, If I don't get my IP talbes running tonite Ill get some help from him becuase he configured it all by hand himself back when it was IPchains.)

 

Its just like a whole set of REALLY BASIC stuff went by and they jumped straight in with the complicated stuff.

 

I like the type this: tutorial ... see why it doesn't do what you expected.

or fun things like alias elvis to your hostname and ping elvis ...

elvis is alive .... :D its all trivial stuff but you use the concepts over and over ....

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...