Run a script from anywhere

Cheetah asked:

I have a script:

#!/bin/bash
echo "$(dirname $(readlink -e $1))/$(basename $1)"

that sits here: /home/myuser/bin/abspath.sh which has execute permissions.

If I run echo $PATH I get the following: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/myuser/bin

I wish to be able to, from any directory, call abspath <some_path_here> and it call my script. I am using bash, what I am doing wrong?

My answer:


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:

  1. Type abspath.sh instead.
  2. Rename the program to abspath.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.