Got a quick question:
I am trying to run scripts in Red Hat 9.0, I include the #!/bin/bash directive, so I try to run the script my typing its name, nothing. If I type "bash script_name" it will run fine. Any way to get around the bash command?
What error do you get?
What are the permissions on the file? Make sure it is executable by the user you are running it as.
Is it in your path? If not then cd to the dir it is in and run:
I do not get any error, it just hard returns back to by prompt. I set the file permission to 777, and I am in the correct directory. The ./ worked...I thought there was a way to make it work by just typing the file name...am I wrong?
Yes you need to put it somewhere in your path. eg:
So the script would be:
your_script will work.
To be more precise, you either need to specify the directory where the script is (e.g. ./your_script, or /home/yourname/your_script, etc.) or put it in a directory listed in the PATH environment variable (seperated by colons ':'). Normally the directories /usr/local/bin:/usr/bin:/bin are in the PATH var. This is arranged by your distribution. To see the directories where the shell will find the script by itself through the PATH var, type:
If you put your script in one of the directories you see, you can just type its name (without ./ ).
You can also include a directory of your choice to the PATH var, say the directory "myscripts" in your home directory. Make sure this dir exists, put you script there, and type:
By convention a directory named "bin" is used for this. Some distributions arrange for the bin directory as a subdir of your homedir to be included automatically. This is done by some lines in your ~/.bashrc or ~/.bash_profile or maybe ~/.profile. These lines resemble somthing like:
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
To have you custom dir "/home/yourname/myscripts" permanently in the PATH var. Add the following line at the end of your ~/.bashrc or ~/bash_profile:
Hope this helps.
FYI: You can also put "." in your PATH and then the current directory is searched, much like in DOS. Generally, however, this is not recommended, though I personally prefer it for my non-root development user.
e.g. put in your ~/.bashrc:
Or something of the sort. If you do put "." in your PATH, you should make it the last thing in the PATH.
|All times are GMT -5. The time now is 06:14 PM.|