It is currently Sat, 25 Oct 2014 21:05:00 GMT



 
Author Message
 basename in PS1 on ksh
Hi,

I have the next PS1 in my .profile:

export PS1="`hostname -s`:`whoami`:`basename $PWD`>"

I want the basename of the actual path at the end of the prompt, but
this command is not good. Any idea ?

Thanks,
Jose Luis.



 Sun, 28 May 2006 18:22:46 GMT   
 basename in PS1 on ksh

jose luis fernandez diaz wrote:

Yes, write a "cd" function that sets PS1, e.g. put this in your .kshenv
(or whatever $ENV is set to) if you're using ksh:

export UNAME=`hostname -s`
export MYNAME=`whoami`
if echo "$-"|grep i && test "`alias cd 2>/dev/null`" != "cd=cdprompt"
then
         function cdprompt
         {
                 \cd ${1:-$HOME}
                 echo "                          $PWD"
                 PS1="${UNAME}:${MYNAME}:`basename $PWD`> "
         }
         alias cd=cdprompt
fi

You should really move the setting of UNAME and MYNAME into your
.profile so they only get set when you log in.

Regards,

     Ed.



 Sun, 28 May 2006 23:45:57 GMT   
 basename in PS1 on ksh
On 10 Dec 2003 02:22:46 -0800, jose luis fernandez diaz
Change the double quotes to single, otherwise $PWD is evaluated only
once when the export command is given.

--
Thanks to Nigeria, any email with the word "urgent" in the subject
or address will be deleted.



 Mon, 29 May 2006 01:27:17 GMT   
 basename in PS1 on ksh
jose_luis_fdez_diaz_n...@yahoo.es (jose luis fernandez diaz) wrote in message <news:c2f95fd0.0312100222.1d4b1fc0@posting.google.com>...

I have found other solution:

export PS1="`hostname -s`:`whoami`:`echo '${PWD##*/}'`>"

Regards,
Jose Luis



 Mon, 29 May 2006 17:23:59 GMT   
 basename in PS1 on ksh
2003-12-11, 01:23(-08), jose luis fernandez diaz:
[...]

Which is the same as:

PS1=`hostname -s`:`whoami`:'${PWD##*/}>'

Note that the PS1 variable is specific to each shell, so
shouldn't be exported and shouldn't be put in the .profile file
but in the shell customization file such as .zshrc, .bashrc or
whatever filename for your shell.

bash:

PS1='\h:\u:\W>'

zsh:

PS1='%m:%n:%1/>'

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]



 Mon, 29 May 2006 17:48:02 GMT   
 basename in PS1 on ksh

You are right.

Regards,
Jose Luis.



 Tue, 30 May 2006 03:04:39 GMT   
 
   [ 6 post ] 

Similar Threads

1. PS1 peculiarity both in ksh and sh!

2. Displaying time in PS1 prompt (ksh on HPUX 9.01 or 10.0)

3. ksh: $PWD in $PS1 doesn't change with directories

4. Making PS1 to appear bold in ksh

5. PS1 in ksh

6. PS1 in KSH and Directories

7. KSH Question about the PS1

8. help with PS1=$PWD in ksh

9. PS1 in ksh (~/my-dir)

10. put time in ksh PS1: Examples on Kornshell book page 88 does not work


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software