bug-bash
[Top][All Lists]
Advanced

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

Re: Tilde expansion during command search


From: Dan Douglas
Subject: Re: Tilde expansion during command search
Date: Wed, 23 Jul 2014 09:02:13 -0500
User-agent: KMail/4.13.3 (Linux/3.16.0-rc5; KDE/4.13.3; x86_64; ; )

On Wednesday, July 23, 2014 07:58:26 AM Eric Blake wrote:
> On 07/23/2014 07:51 AM, Dan Douglas wrote:
> > On Wednesday, July 23, 2014 09:28:02 AM you wrote:
> >> On 7/23/14, 8:22 AM, Dan Douglas wrote:
> >>> Hi, from this discussion:
> >>>
> >>> https://github.com/koalaman/shellcheck/issues/195#issuecomment-49678200
> >>>
> >>> I can't find any reference that says substituting a literal tilde in PATH 
> >>> should occur during command search.
> >>
> >> Bash has always done this, even back to the pre-version 1 days, and I don't
> >> see any reason to change it now.
> >>
> > 
> > The only concerns I can think of are inconsistency with programs that use 
> > execvp(), or possibly double-expansion in the event of a user name or any 
> > path 
> > containing ~.
> > 
> > You're probably right in that it's not super critical if it hasn't caused 
> > problems so far.
> 
> Might be worth asking the POSIX folks if it is allowed by POSIX.  What
> do other shells do?
> 

I tested it in the link from my first post. AFAICT Bash is the only one.

#!/bin/bash
printf '%s\n' '#!/bin/sh' 'echo test' >~/tmpdir/testscript
chmod u+x ~/tmpdir/testscript
s=(bash ksh mksh posh zsh dash bb jsh)

# Testing for parameter expansion.
for sh in "${s[@]}"; do
    printf '%-4s %s\n' "${sh}:" "$("$sh" -c 'PATH=\${HOME}/tmpdir; testscript' 
2>&1)"
done
echo

# Testing for tilde expansion.
for sh in "${s[@]}"; do
    printf '%-4s %s\n' "${sh}:" "$("$sh" -c 'PATH=\~/tmpdir; testscript' 2>&1)"
done

bash: bash: testscript: command not found
ksh: ksh: testscript: not found
mksh: mksh: testscript: not found
posh: posh: testscript: not found
zsh: zsh:1: command not found: testscript
dash: dash: 1: testscript: not found
bb:  bb: testscript: not found
jsh: jsh: testscript: not found

bash: test
ksh: ksh: testscript: not found
mksh: mksh: testscript: not found
posh: posh: testscript: not found
zsh: zsh:1: command not found: testscript
dash: dash: 1: testscript: not found
bb:  bb: testscript: not found
jsh: jsh: testscript: not found

-- 
Dan Douglas

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

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