AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  PS1 prompt: how to remove HOME directory

    Posted Mon November 19, 2007 08:38 AM

    Originally posted by: SystemAdmin


    Hi,
    I'm try to find the way to remove the $HOME directory from $PWD command.

    Actually I have this set in .profile
    export PS1='$USER@$HOSTNAME:${PWD}>'

    For some users, the home directory very long (more than 20 chars). developers are asking me how we can have the working directory, but without the HOME path.

    Example:
    <hr />
    [appc49@oas23/fslnxc49/applmgr/gpsogc49>echo $HOME
    /fslnxc49/applmgr/gpsogc49/
    appc49@oas23/fslnxc49/applmgr/gpsogc49>echo $PS1
    $USER@oas23$PWD>
    appc49@oas23/fslnxc49/applmgr/gpsogc49>
    appc49@oas23/fslnxc49/applmgr/gpsogc49/appl/admin/gpsogp14_806_BALANCE>
    <hr />
    They want this
    appc49@oas23appl/admin/gpsogp14_806_BALANCE>

    Any idea?
    Mike


  • 2.  Re: PS1 prompt: how to remove HOME directory

    Posted Mon November 19, 2007 09:26 AM

    Originally posted by: MarkTaylor


    How about something like this ..

    PS1="${USER}@${HOSTNAME}:/\${PWD##*/} > "

    This will drop the whole path and leave you the current working dir preceded my a slash "/".. how many dirs depth do you want to drop ?

    HTH
    Mark Taylor

    Message was edited by: MarkTaylor


  • 3.  Re: PS1 prompt: how to remove HOME directory

    Posted Mon November 19, 2007 09:34 AM

    Originally posted by: SystemAdmin


    Thanks Mark for the hint.
    The output is not the one that I'm looking for. Infact this will return the Last working directory:

    --
    total 0
    appc49@oasitfi23npge:/gpsogp14_806_BALANCE > pwd
    /fslnxc49/applmgr/gpsogc49/appl/admin/gpsogp14_806_BALANCE
    appc49@oasitfi23npge:/gpsogp14_806_BALANCE >
    ---
    My need is to have as result "appl/admin/gpsogp14_806_BALANCE"

    Mike


  • 4.  Re: PS1 prompt: how to remove HOME directory

    Posted Mon November 19, 2007 11:57 AM

    Originally posted by: MarkTaylor


    Yup, thats right, just does a basename by shell substitution to give the current working dir on its own without the full path .. Ok, give this a go .. this should remove $HOME from the $PWD variable .. (ksh)

    export PS1="\${PWD%%${HOME}} > "

    This means when they are in thier home dir all they will get it " > " .. but this is what you wanted ?

    HTH
    Mark Taylor


  • 5.  Re: PS1 prompt: how to remove HOME directory

    Posted Mon November 19, 2007 12:05 PM

    Originally posted by: SystemAdmin


    Hi Mark, u got the point. This is what I'd like to have as Prompt.

    Unfortunately the command u gave me is not working on ksh AIX 5.2

    export PS1="\${PWD%%${HOME}} > "
    --
    appp14@rs12edp/fsaixp14/applmgr/gpsogp14>echo $PS1
    ""${USER}@${SITENAME}""$PWD>
    appp14@rs12edp/fsaixp14/applmgr/gpsogp14>export PS1="\${PWD%%${HOME}} > "
    cd appl
    /fsaixp14/applmgr/gpsogp14/appl > cd admin
    /fsaixp14/applmgr/gpsogp14/appl/admin > cd gpsogp14_806_BALANCE
    /fsaixp14/applmgr/gpsogp14/appl/admin/gpsogp14_806_BALANCE > cd log
    /fsaixp14/applmgr/gpsogp14/appl/admin/gpsogp14_806_BALANCE/log >
    ---
    I did something wrong?
    Mike


  • 6.  Re: PS1 prompt: how to remove HOME directory

    Posted Mon November 19, 2007 03:21 PM

    Originally posted by: MarkTaylor


    Sorry mike, I think I cut an pasted the wrong line, I was playing with delimiting the first dollar sign, just drop the leading slash .. ala:

    export PS1="${PWD%%${HOME}} > "

    I dont have a terminal connection from here at the moment, but I will double check tomorrow and paste the command if it is not that one above ..

    Rgds
    Mark Taylor


  • 7.  Re: PS1 prompt: how to remove HOME directory

    Posted Tue November 20, 2007 04:43 AM

    Originally posted by: SystemAdmin


    Still doens't work...

    appp14@oas21/fslnxp14/applmgr/gpsogp14>export PS1="${PWD%%${HOME}} > "
    /fslnxp14/applmgr/gpsogp14 > cd appl
    /fslnxp14/applmgr/gpsogp14 > cd admin
    /fslnxp14/applmgr/gpsogp14 > pwd
    /fslnxp14/applmgr/gpsogp14/appl/admin
    /fslnxp14/applmgr/gpsogp14 >
    Mike


  • 8.  Re: PS1 prompt: how to remove HOME directory

    Posted Tue November 20, 2007 05:13 AM

    Originally posted by: MarkTaylor


    didn't do enough testing :)

    this seems to work though

    /usr/local/log > export PS1="\${PWD##${HOME}} > "
    /usr/local/log > cd /tmp
    /tmp > echo $HOME
    /home/root
    /tmp > cd $HOME
    cd Mail
    /Mail >

    Rgds
    Mark Taylor


  • 9.  Re: PS1 prompt: how to remove HOME directory

    Posted Tue November 20, 2007 09:56 AM

    Originally posted by: SystemAdmin


    This is working!!!
    Thanks a lot..

    My next step is to add the ~ value at the beginnin, replacing the HOME....

    Mike