Date: Mon, 18 Jul 2005 01:45:03 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Alex Yarmol <alex.yarmol@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: Bash prompt Message-ID: <20050717224503.GE1291@gothmog.gr> In-Reply-To: <f1b7642105071714301ee2a19b@mail.gmail.com> References: <f1b7642105071714301ee2a19b@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-07-18 00:30, Alex Yarmol <alex.yarmol@gmail.com> wrote: > Hi, dear FreeBSD developers etc. :) > > I have a question. > > How I can chage my bash prompt to this: > > [user@host directory-name(e. g. "alex" for /usr/home/alex)]$ > > I assume that I need to do that: > > export PS1='[\u@\h \(here i don't know what to do, i assume, that I > need to write "\p" or "\P", but it's not working)]\$ > > I've try to read "man bash", but didn't find what I want :( The manpage of bash(1) contains a section called ``PROMPTING'' that explains all the "backslash-starting escape sequences" you can use. Having said that though, the real ``working directory'' cannot be inlined in the PS1 shell variable by using an escape. The closest one can come up with is something that uses ``\w'', but this is not quite right, because it changes the HOME directory to ``~'' and there is no way to turn that off (at least, AFAIK). A workaround for this is to embed a literal ``${PWD}'' in the value of PS1, but you have to be careful to AVOID having this expanded only at the time PS1 is set, by using the proper sort of quote characters. Something like this won't work: $ export PS1="[\u@\h ${PWD}]\$ " because the shell is allowed to expand the contents of "..." quoted strings. The correct way to set PS1 using inline escape sequences and references to environment variables like ``$PWD'', which may change between subsequent PS1 references by the shell, is with something that uses single quotes: $ export PS1='[\u@\h ${PWD}]\$ ' I hope this helps a bit. If you need more details, there's a whole HOWTO document describing a lot more details than any sane person is ever going to need about bash prompts. You can find it on any mirror of the Linux Documentation Project. Since the GNU bash shell runs on both Linux and FreeBSD, most of it applies verbatim to FreeBSD too. - Giorgos
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050717224503.GE1291>