Account Links: Cart | Your Account | Logout

Skip to content

Red Hat Knowledgebase

Red Hat Knowledgebase Search:

Updated Within the Last:

New Solutions within the last day New Solutions within the last week New Solutions within the last month

Browse by topics:


Click to View a Topic
Red Hat Enterprise Linux > AS/ES/WS v. 3 > Issue <<  403 of 594 >>

Solution Tools:


Email a Solution Postcard Printer version Submit a comment on this answer Update notifications Request an answer Back

Article Reference

Article ID: 4118
Last update: 11-02-04
Issue:
Why do I get the error 'bash: hotbackup.sh: command not found' when trying to run a shell script titled hotbackup.sh?
Resolution:
The directory containing the shell script, 'hotbackup.sh', is not listed in your PATH environment variable. Bash, like most other Unix shells (sh, ksh, and csh for example) use the PATH environment variable to find shell scripts and other programs for execution.

The PATH environment variable is a colon separated list of directory names. You can see the current value of your PATH environment variable with the command echo $PATH. For example:

 
# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:
/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
      


In Bash, you can add a directory to you PATH environment variable with the command PATH=$PATH:/some/new/directory, replacing /some/new/directory with the absolute path name of the directory you want to add to your PATH environment variable. For example, if I wanted to add the home directory of the username, wolfpack, I would do the following:

 
# PATH=$PATH:/home/wolfpack
# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:
/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/home/wolfpack
      


See the Bash man page (or the man page for your specific Unix shell) for information on how to set and change environment variables.

When Bash, and most other Unix shells, is given a command that does not contain a slash, it will search each directory listed in the PATH environment variable for a file with the same name as the command. If it finds such a file, it will attempt to run it. If it does not find such a file, Bash will give the error message bash: hotbackup.sh: command not found.

If the command contains a slash, Unix shells will assume the command is directly naming a file to be executed. If that file does not exist, Bash will give the error bash: /home/gavin/foo: No such file or directory. Using this you can execute any shell script without having Bash search the PATH environment variable. For example, if the shell script 'hotbackup.sh' is in your current directory, you can simply use the command './hotbackup.sh' to execute it. Otherwise you will have to provide the full path to the filename.


How well did this entry answer your question?


good wrong incomplete out of date
Red Hat Enterprise Linux > AS/ES/WS v. 3 > Issue <<   403  of  594  >>