So I have a function that I wish to run from my command line.
cat foo.sh
#!/bin/bash
echo foobar
I export it to my PATH variable and change to a different directory.
export PATH=${PATH}:/home/usr/scripts/foo.sh
mkdir test && cd test
sh foo.sh
sh: foo.sh: No such file or directory
If i run it like so foo.sh
I get bash: foo.sh: command not found
.
I could run it with the absolute path, but I didn't think I would need to if I added it to my $PATH. What mistake am I making here?
Thanks.
PATH
should contain paths, not files i.e.PATH=${PATH}:/home/usr/scripts
sh foo.sh
in a different directory still won't work even if you fix the PATH, this tellssh
to run the filefoo.sh
in the current directory.