2 Replies Latest reply: Sep 23, 2010 1:47 PM by 807559 RSS

    Confused by PS1 in Solaris 9

      For years I have had the current working path in my PS1 prompt on many different systems -- AIX, Solaris and Linux.
      I am at a new place and am trying to set this up again, but I can't seem to get it to work so that when I change directories, the new location is reflected in the prompt.
      I am noticing that when I issue "set" PS1 is displayed as PS1='host:path'. That is, there are single quotes around the resolved $(hostname):$(pwd) values.

      If the above is not clear

      I put into my .profile


      After saving .profile, I enter the command

      . ./.profile

      The prompt looks right.
      then I enter


      and what is displayed for PS1 is


      if I then change the directory

      cd ..

      the prompt does not change.
      I want the prompt to change.

      Hopefully this is clear enough.

      So, what am I not remembering, and thus doing wrong.

      Edited by: Chasman on Sep 16, 2010 10:25 AM
        • 1. Re: Confused by PS1 in Solaris 9
          You're probably using bash syntax and your shell on Solaris is not bash.

          Change your shell to bash.

          • 2. Re: Confused by PS1 in Solaris 9
            bash has nothing to do with it, this is Solaris and Korne shell.

            Finally found the answer ==> PS1="\$PWD"
            That is the basic form to get the current working directory into the prompt so that it will change/update whenever you enter the cd command.

            You must use double quotes.
            You must quote the $ with a back-slash
            You must use the PWD variable, not the pwd command -- note the case.
            use of braces is optional ==> PS1="\${PWD}"

            I though I remembered being able to use $(pwd), but I must have been wrong -- misremembered.

            So, what I have in my .profile is

            tty -s
            if [ $? -eq 0 ]
            export PAGER=less
            export EDITOR=vi

            this produces a prompt like:




            that way, when I change the directory to some long path, I still get to know where I am, and not obscure the next command I enter; e.g.

            $cd /usr/adm/best1_default/bgs/monitor/log


            Hope this helps someone