From owner-freebsd-questions@FreeBSD.ORG Sun Jul 17 22:45:11 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9757816A41C for ; Sun, 17 Jul 2005 22:45:11 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from rosebud.otenet.gr (rosebud.otenet.gr [195.170.0.94]) by mx1.FreeBSD.org (Postfix) with ESMTP id EDB6143D46 for ; Sun, 17 Jul 2005 22:45:07 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-a098.otenet.gr [212.205.215.98]) by rosebud.otenet.gr (8.13.4/8.13.4/Debian-1) with ESMTP id j6HMj5mM019871; Mon, 18 Jul 2005 01:45:05 +0300 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.13.4/8.13.4) with ESMTP id j6HMj4vS001658; Mon, 18 Jul 2005 01:45:04 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.13.4/8.13.4/Submit) id j6HMj3K3001657; Mon, 18 Jul 2005 01:45:03 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Mon, 18 Jul 2005 01:45:03 +0300 From: Giorgos Keramidas To: Alex Yarmol Message-ID: <20050717224503.GE1291@gothmog.gr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Cc: freebsd-questions@freebsd.org Subject: Re: Bash prompt X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jul 2005 22:45:11 -0000 On 2005-07-18 00:30, Alex Yarmol 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