1

How do you change your prompt variable to display the current working directory (pwd), meaning so that when a directory is changed the prompt also changes to reflect the current directory you are in

3
  • Doesn't the default prompt do that?
    – muru
    Sep 20, 2014 at 18:01
  • No need to change anything, it is the already the default behavior of shell until you are not messing with PS1 variable.
    – g_p
    Sep 20, 2014 at 18:01
  • 1
    @muru well the question would warrant the assumption he is not using the default prompt or not bash ;)
    – Rinzwind
    Sep 20, 2014 at 18:04

1 Answer 1

1

I'm pretty certain the default prompt already does that, but here it is, for reference:

muru@muru-pc:~$ echo $PS1
${debian_chroot:+($debian_chroot)}\u@\h:\w\$

The important bit is the \w part. You can set it to \W for only the name of the current directory (basename $(pwd)).

Check out the full list at TLDP.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .