Well, if not confused. In addition, they do not match:
$ date=/bin/ls $ type date date is hashed (/bin/date) $ type $date /bin/ls is /bin/ls $ moo=foo $ type $moo -bash: type: foo: not found $ function date() { true; } $ type date date is a function date () { true*emphasized text* } $ which true /bin/true $ type true true is a shell builtin
Whenever you enter a command, bash looks in three different places to find this command. Priority is as follows:
- built-in shells (help)
- shell aliases (help alias)
- Shell Functions (help function)
- hashes binary files from $ PATH (first look at the "leftmost" folders)
Variables have a dollar sign prefix, which distinguishes them from all of the above. For comparison with your example: $ date and date are not the same thing. So it’s actually impossible to have the same name for a variable and function because they have different “namespaces”.
You may find this somewhat confusing, but many scripts define "method variables" at the top of the file. eg.
SED=/bin/sed AWK=/usr/bin/awk GREP/usr/local/gnu/bin/grep
The generally accepted task is to type the names of variables in capitals. This is useful for two purposes (besides less confusing):
- No $ PATH
- Validating all dependencies
You really cannot verify this:
if [ "`which binary`" ]; then echo it\ ok to continue.. ;fi
Because it will give you an error if the binary has not yet been hashed (found in the path folder).
source share