ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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:
echo $PATH
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:
export PATH=${PATH}:${HOME}/myscripts
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
PATH=~/bin:"${PATH}"
fi
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:
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:
PATH=$PATH:.
Or something of the sort. If you do put "." in your PATH, you should make it the last thing in the PATH.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.