Run a script from anywhere
You want to type abspath
, but the program is named abspath.sh
. The problem is not regarding whether it is in the PATH, but the fact that you are simply not using its name to call it.
You have two options:
- Type
abspath.sh
instead. - Rename the program to
abspath
.
This code is small enough that I would code it as a shell function:
abspath() {
echo "$(dirname "$(readlink -e "$1")")/$(basename "$1")"
}
And yes you do want all those quotes.
set an alias by adding your command in .bashrc file.
alias abspath='sh /home/myuser/bin/abspath.sh'
And don't forget to source the file.