dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] $PATH not fully searched
@ 2018-01-10 18:36 Joshua Nelson
  2018-01-10 22:18 ` Jilles Tjoelker
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Nelson @ 2018-01-10 18:36 UTC (permalink / raw)
  To: dash; +Cc: cdaniels

[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

To the maintainers of the `dash` shell:

I've come across an error with the PATH variable in `dash`. Instead of fully 
searching PATH for commands, dash will respond 'command not found' if `command 
-p <executable>` fails.  The same command works fine in Bash.

The following example was performed in a live cd of Debian 9.1 Stretch (run in 
a virtual machine), with dash version 0.5.8-2.4:

```bash
user@debian:~$ PATH="~/my_bin:$PATH" dash
$ echo $PATH
~/my_bin:/usr/local/bin:/usr/bin:/usr/local/games:/usr/games
$ ls -l ~/my_bin/list
-rwxr--r-- 1 user user 18 Jan 10 17:42 /home/user/my_bin/list
$ list
dash: 3: list: not found
$ exit
user@debian:~$ PATH="$PATH:~/my_bin" list
Desktop Documents Downloads Music my_bin Pictures Public Templates Videos
```

I believe but am not certain that this is related to the following patch:
https://www.mail-archive.com/dash@vger.kernel.org/msg01329.html

Thank you for your time,
Joshua Nelson

jynelson@email.sc.edu
B.S. Computer Science
College of Engineering and Computing | South Carolina Honors College
This message was sent with a PGP[1] signature.

--------
[1] https://www.openpgp.org/

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] $PATH not fully searched
  2018-01-10 18:36 [BUG] $PATH not fully searched Joshua Nelson
@ 2018-01-10 22:18 ` Jilles Tjoelker
  2018-01-10 23:44   ` Joshua Nelson
  0 siblings, 1 reply; 3+ messages in thread
From: Jilles Tjoelker @ 2018-01-10 22:18 UTC (permalink / raw)
  To: Joshua Nelson; +Cc: dash, cdaniels

On Wed, Jan 10, 2018 at 01:36:18PM -0500, Joshua Nelson wrote:
> I've come across an error with the PATH variable in `dash`. Instead of
> fully searching PATH for commands, dash will respond 'command not
> found' if `command -p <executable>` fails.  The same command works
> fine in Bash.

> The following example was performed in a live cd of Debian 9.1 Stretch
> (run in a virtual machine), with dash version 0.5.8-2.4:

> ```bash
> user@debian:~$ PATH="~/my_bin:$PATH" dash
> $ echo $PATH
> ~/my_bin:/usr/local/bin:/usr/bin:/usr/local/games:/usr/games
> $ ls -l ~/my_bin/list
> -rwxr--r-- 1 user user 18 Jan 10 17:42 /home/user/my_bin/list
> $ list
> dash: 3: list: not found
> $ exit
> user@debian:~$ PATH="$PATH:~/my_bin" list
> Desktop Documents Downloads Music my_bin Pictures Public Templates Videos
> ```

> I believe but am not certain that this is related to the following patch:
> https://www.mail-archive.com/dash@vger.kernel.org/msg01329.html

In your example, the tilde is quoted and ends up literally in PATH.
Then, in bash only, tilde expansion is attempted again during the
search. In my testing, zsh, mksh, ksh93, dash and FreeBSD sh do not
implement this feature. Enabling POSIX mode in bash also disables the
feature.

What works more portably is
  PATH=~/my_bin:$PATH dash
or
  PATH=$PATH:~/my_bin list
which expands the tilde at the time of the assignment. This works pretty
much everywhere except in old real Bourne shells, which do not implement
tilde expansion at all.

If you want to quote the $PATH part, it is possible but not necessary
since it is in a variable assignment which is not subject to pathname
generation and word splitting anyway. However, if "export" is prepended,
I strongly recommend quoting it since some shells such as dash do not
implement the special rule for assignment utilities yet.

-- 
Jilles Tjoelker

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] $PATH not fully searched
  2018-01-10 22:18 ` Jilles Tjoelker
@ 2018-01-10 23:44   ` Joshua Nelson
  0 siblings, 0 replies; 3+ messages in thread
From: Joshua Nelson @ 2018-01-10 23:44 UTC (permalink / raw)
  To: Jilles Tjoelker; +Cc: dash, cdaniels

[-- Attachment #1: Type: text/plain, Size: 2156 bytes --]

This was precisely the problem! Thanks so much for your help,
I changed the relevant parts of ~/.profile to "$HOME/<path>" instead.

On Wednesday, January 10, 2018 23:18:15 EST Jilles Tjoelker wrote:
> On Wed, Jan 10, 2018 at 01:36:18PM -0500, Joshua Nelson wrote:
> > I've come across an error with the PATH variable in `dash`. Instead of
> > fully searching PATH for commands, dash will respond 'command not
> > found' if `command -p <executable>` fails.  The same command works
> > fine in Bash.
> > 
> > The following example was performed in a live cd of Debian 9.1 Stretch
> > (run in a virtual machine), with dash version 0.5.8-2.4:
> > 
> > ```bash
> > user@debian:~$ PATH="~/my_bin:$PATH" dash
> > $ echo $PATH
> > ~/my_bin:/usr/local/bin:/usr/bin:/usr/local/games:/usr/games
> > $ ls -l ~/my_bin/list
> > -rwxr--r-- 1 user user 18 Jan 10 17:42 /home/user/my_bin/list
> > $ list
> > dash: 3: list: not found
> > $ exit
> > user@debian:~$ PATH="$PATH:~/my_bin" list
> > Desktop Documents Downloads Music my_bin Pictures Public Templates Videos
> > ```
> > 
> > I believe but am not certain that this is related to the following patch:
> > https://www.mail-archive.com/dash@vger.kernel.org/msg01329.html
> 
> In your example, the tilde is quoted and ends up literally in PATH.
> Then, in bash only, tilde expansion is attempted again during the
> search. In my testing, zsh, mksh, ksh93, dash and FreeBSD sh do not
> implement this feature. Enabling POSIX mode in bash also disables the
> feature.
> 
> What works more portably is
>   PATH=~/my_bin:$PATH dash
> or
>   PATH=$PATH:~/my_bin list
> which expands the tilde at the time of the assignment. This works pretty
> much everywhere except in old real Bourne shells, which do not implement
> tilde expansion at all.
> 
> If you want to quote the $PATH part, it is possible but not necessary
> since it is in a variable assignment which is not subject to pathname
> generation and word splitting anyway. However, if "export" is prepended,
> I strongly recommend quoting it since some shells such as dash do not
> implement the special rule for assignment utilities yet.
> 
> --
> Jilles Tjoelker

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-10 23:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 18:36 [BUG] $PATH not fully searched Joshua Nelson
2018-01-10 22:18 ` Jilles Tjoelker
2018-01-10 23:44   ` Joshua Nelson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).