1

I distinctly remember reading that when $PATH does not include the working directory Linux script invocation requires the path even if the path is ./ and so the script invocation is ./script.sh

Apparently this is not the case with 14.04.3 LTS, that is script.sh invokes.

What are the circumstances when ./ is required?

> echo '#!/bin/bash' > test.sh
> echo 'pwd' >> test.sh
> cat test.sh
#!/bin/bash
pwd
> chmod +x test.sh
> test.sh
/home/brian/Desktop/test
> ./test.sh
/home/brian/Desktop/test
> echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/brian/Documents/bashscripts:
> echo 'pwd' > test2.sh
> chmod +x test2.sh
> test2.sh
/home/brian/Desktop/test

> echo "$PATH" | od -c
0000000   /   u   s   r   /   l   o   c   a   l   /   s   b   i   n   :
0000020   /   u   s   r   /   l   o   c   a   l   /   b   i   n   :   /
0000040   u   s   r   /   s   b   i   n   :   /   u   s   r   /   b   i
0000060   n   :   /   s   b   i   n   :   /   b   i   n   :   /   h   o
0000100   m   e   /   b   r   i   a   n   /   D   o   c   u   m   e   n
0000120   t   s   /   b   a   s   h   s   c   r   i   p   t   s   :  \n
0000140
> 
0

1 Answer 1

2

The reason being your $PATH ending in a : which automatically appends the current working directory to the PATH.

So you need to remove the trailing :

export PATH="${PATH%:}"

Example:

$ PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:
$ bar.sh 
Foobar

$ PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ bar.sh
bar.sh: command not found

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .