Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
books say that PATH variable contains the locations where the shell searches the commands to execute them.
I created a shell script and saved it in /home/user/Downloads directory and then i ran this script from the /home/user/Downloads directory. It did not execute.
however when i did set the path export PATH=$PATH:/bin/sh within /home/user/Downloads directory, the shell script executed. Does it not mean that PATH variable is holding the locations of the shell program rather than the commands that are to be executed?
everytime i have to give the location of the shell i.e /bin/sh in the PATH variable no matter from where i am executing my script
Last edited by Upendra Pratap Singh; 02-09-2015 at 10:47 AM.
Reason: provide extra information
books say that PATH variable contains the locations where the shell searches the commands to execute them.
That is correct.
Quote:
I created a shell script and saved it in /home/user/Downloads directory and then i ran this script from the /home/user/Downloads directory. It did not execute.
however when i did set the path export PATH=$PATH:/bin/sh within /home/user/Downloads directory, the shell script executed. Does it not mean that PATH variable is holding the locations of the shell program rather than the commands that are to be executed?
everytime i have to give the location of the shell i.e /bin/sh in the PATH variable no matter from where i am executing my script
Right...so when you set the path, the system knows where to look for commands. Nothing wrong there. So either move your script to a directory that's already in your path, or modify it to include whatever directory you want. Your "books" should also have told you this, too. Modify your path by editing your .bashrc/.profile/.bash_profile file (whichever applies), and each time you launch a shell, that PATH will be set.
Also, this goes well with your other homework-sounding question, and given that you've been using Linux for four years now, seems a bit odd.
books say that PATH variable contains the locations where the shell searches the commands to execute them.
I created a shell script and saved it in /home/user/Downloads directory and then i ran this script from the /home/user/Downloads directory. It did not execute.
however when i did set the path export PATH=$PATH:/bin/sh within /home/user/Downloads directory, the shell script executed. Does it not mean that PATH variable is holding the locations of the shell program rather than the commands that are to be executed?
everytime i have to give the location of the shell i.e /bin/sh in the PATH variable no matter from where i am executing my script
Wrong. We only pass directories to the PATH variable and not location of executable like /bin/sh.
Wrong. We only pass directories to the PATH variable and not location of executable like /bin/sh.
Please re-read what was posted. The OP said they had to give a location to the shell, FOR EXAMPLE, /bin/sh. Since /bin/sh IS the fully-qualified path to sh, there is NOTHING wrong with that. All that says, is that /bin is NOT in the OP's path.
Please don't post incorrect or misleading information.
Please re-read what was posted. The OP said they had to give a location to the shell, FOR EXAMPLE, /bin/sh. Since /bin/sh IS the fully-qualified path to sh, there is NOTHING wrong with that. All that says, is that /bin is NOT in the OP's path.
Please don't post incorrect or misleading information.
Quote:
Does it not mean that PATH variable is holding the locations of the shell program rather than the commands that are to be executed?
So in your case, if your script is located in /home/user/Downloads you need to add this directory into PATH: PATH=$PATH:/home/user/Downloads in order to look for your script to execute it (because you want to execute your script, not /bin/sh).
Putting the literal path to an executable into PATH doesn't work. PATH should hold directories:
Code:
$ PATH=/usr/local/bin
$ ls
bash: ls: command not found
$ PATH=/usr/local/bin:/usr/bin/ls
$ ls
bash: ls: command not found
$ PATH=/usr/local/bin:/usr/bin/
$ ls
$
The OP may or may not have meant that (perhaps it's ambiguous, though I do read it the same way as veerain does).
So in your case, if your script is located in /home/user/Downloads you need to add this directory into PATH: PATH=$PATH:/home/user/Downloads in order to look for your script to execute it (because you want to execute your script, not /bin/sh).
the situation still persists.
When i have given the path as /home/user/Downloads and when i try to execute from some other location, it says that file does not exists. But did I not put the path in the first place. Then why am I getting such a message
When i have given the path as /home/user/Downloads and when i try to execute from some other location, it says that file does not exists. But did I not put the path in the first place. Then why am I getting such a message
You need to back up and describe what, EXACTLY, you're setting the PATH to, and what, EXACTLY, you're trying to run. Don't just say "I'm doing X", you need to copy and paste the actual terminal output, both your commands and the result, in order for anybody to help you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.