1

In Dash if I set the PATH to an empty string, it searches in current directory:

$ export PATH=
$ echo $PATH

$ emptyexe
$ /usr/bin/ls emptyexe
emptyexe
$ pwd
/home/ctor
$ cd ..
$ emptyexe
dash: 36: emptyexe: not found

What do I set PATH to so that it's guaranteed to not search in any directory, least of all the current one ?

An empty PATH also searches the current directory in Bash, so the question applies to it, too.

This is on Fedora 28 (an AppVM in Qubes OS actually):

$ rpm -qf `which dash`
dash-0.5.9-1.fc25.x86_64
$ rpm -qf `which bash`
bash-4.3.43-4.fc25.x86_64
3
  • 1
    I removed the part of your post that was actually a separate question (as you said yourself, it's a separate issue). It only worked to confuse readers from the question you set in the title. You can post the other question as, well, another question.
    – ilkkachu
    Sep 8, 2018 at 20:37
  • @ilkkachu Thank you, it is much cleaner now! Cheers!
    – user306023
    Sep 8, 2018 at 21:05
  • 1
    Just for reference, the bash manual does describe this behavior in Section 5.1 Bourne Shell Variables: "A colon-separated list of directories in which the shell looks for commands. A zero-length (null) directory name in the value of PATH indicates the current directory."
    – Jeff Schaller
    Sep 9, 2018 at 15:09

1 Answer 1

3

For example $ export PATH=/dev/null should do it.

[ctor@dom0 ~]$ dash
$ echo 'echo meh' > nonemptyexe
$ /usr/bin/chmod a+x ./nonemptyexe
$ nonemptyexe
dash: 3: nonemptyexe: not found
$ ./nonemptyexe
meh
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/ctor/.local/bin:/home/ctor/bin
$ export PATH=/dev/null
$ nonemptyexe
dash: 7: nonemptyexe: not found
$ ./nonemptyexe
meh
$ echo $PATH
/dev/null
$ export PATH=""
$ echo $PATH

$ nonemptyexe
meh
$ ./nonemptyexe
meh
$ 

You must log in to answer this question.