LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-09-2015, 10:39 AM   #1
Upendra Pratap Singh
Member
 
Registered: May 2011
Location: India
Distribution: Ubuntu 14.04
Posts: 110
Blog Entries: 4

Rep: Reputation: 0
what exactly is PATH


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
 
Old 02-09-2015, 10:53 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,785

Rep: Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159
Quote:
Originally Posted by Upendra Pratap Singh View Post
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.
 
Old 02-09-2015, 11:16 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by Upendra Pratap Singh View Post
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.
 
Old 02-09-2015, 12:47 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,785

Rep: Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159
Quote:
Originally Posted by veerain View Post
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.
 
Old 02-09-2015, 10:31 PM   #5
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
Originally Posted by TB0ne View Post
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?
Quote:
export PATH=$PATH:/bin/sh
See what he posted. That's obviously wrong.
 
Old 02-10-2015, 01:39 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,185

Rep: Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673Reputation: 2673
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).
 
Old 02-10-2015, 08:56 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,785

Rep: Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159Reputation: 4159
Quote:
Originally Posted by veerain View Post
See what he posted. That's obviously wrong.
READ and UNDERSTAND what he posted before saying that. You *CAN* do exactly what he said, and gave that only as an example.
 
Old 02-10-2015, 10:29 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,131

Rep: Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317
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).
 
Old 02-10-2015, 11:19 AM   #9
Upendra Pratap Singh
Member
 
Registered: May 2011
Location: India
Distribution: Ubuntu 14.04
Posts: 110
Blog Entries: 4

Original Poster
Rep: Reputation: 0
Exclamation

Quote:
Originally Posted by pan64 View Post
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
 
Old 02-10-2015, 11:21 AM   #10
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,454

Rep: Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052Reputation: 2052
Quote:
Originally Posted by Upendra Pratap Singh View Post
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
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Installing an extra version of CMake - can run from full path but not from $PATH mattachu Linux - Software 1 05-23-2014 03:58 PM
Strange bash completion behavior when using path with ' (apostroph) in PATH variable mallniya Linux - Newbie 3 02-05-2014 12:41 AM
eval $PATH produces a path list followed by No such file or directory warning Alpha90 Linux - Newbie 10 11-04-2012 10:16 AM
[SOLVED] Perforce edits my files when I give a depot path but not if I specify the local path gregorian Linux - Software 1 10-21-2011 11:57 AM
bash script path issue - how to pass a path as a string to a variable PiNPOiNT Programming 5 04-17-2009 05:48 PM


All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration