1

Some scripts in my company call some functions like hdfs, or cat, echo, etc.

Sometimes, it's done via:

echo "something"

And other times via:

/usr/bin/echo "something"

If any, what is the difference between these two ways of using a command ?

1 Answers1

1

You can tell your login session where to look for executables using an environment variable named PATH, a list of directories separated by a colon.

It has some value set by default, something like this:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

You can also add your own directories, e.g.:

PATH="$HOME/bin:$PATH"

All executables in these directories can be executed directly from anywhere using only its name. echo is in one of these directories. To find out where exactly run:

$ which echo
/bin/echo

Using a full path to an executable can be useful in some cases, as the PATH variable may be different depending on the environment. This can cause problems e.g. when calling scripts via cron.

pLumo
  • 22,565