bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug] Home dir in PS1 not abbreviated to tilde


From: Eric Blake
Subject: Re: [bug] Home dir in PS1 not abbreviated to tilde
Date: Tue, 13 Mar 2012 11:24:05 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1

On 03/13/2012 11:03 AM, dethrophes wrote:
> 
> the missing "" in the case isn't redundant.

It is too redundant; you only need "" after case if the parser would
otherwise see two words before in.

> case "$HOME" in
>    *[^/]* ) HOME=${HOME%${HOME##*[^/]}} ;;
>    / | // ) ;;
>    *) HOME=/ ;; # //+(/)
> esac

By the way, one more tweak to make this example POSIX-compliant rather
than relying on a bash extension - shell pattern matching uses ! for
negation and leaves ^ unspecified (as an extension, bash treats ^ as a
synonym for ! in performing negation, but other shells treat ^
literally).  Additionally, since POSIX requires tilde-expansion to occur
on the word after 'case', you can write this as:

case ~ in
  *[!/]* ) HOME=${HOME%${HOME##*[!/]}} ;;
  / | // ) ;;
  *) HOME=/ ;;
esac

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]