LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-08-2016, 04:21 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Script directory in path


I add my script directory to my path, but still get this when I run a script from any other directory.

Quote:
No such file or directory

Quote:
PATH=/usr/lib/qt/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/root/my-applications/bin:/usr/games:/opt/qt4/bin:/usr/lib/qt/bin:/root/Scripts/
 
Old 02-08-2016, 04:35 PM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Andy:

Did you source the file you used to alter the path?
Your shell won't know about the edit until you do.
https://www.linuxquestions.org/quest...#faq_lqwelcome

Code:
source /path/to/file
script.sh
Try also
Code:
bash -x /path/to/script.sh
 
Old 02-08-2016, 05:26 PM   #3
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I do not understand "source the file." ?

In my .bashrc

export PATH=$PATH:/root/Scripts/

The purpose of adding a dir to the path is to be able to runs scripts from any directory WITHOUT using the full path to it.

I guess Linux does it differently than Windows.
 
Old 02-08-2016, 05:34 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Fixit7 View Post
I do not understand "source the file." ?

In my .bashrc

export PATH=$PATH:/root/Scripts/

The purpose of adding a dir to the path is to be able to runs scripts from any directory WITHOUT using the full path to it.

I guess Linux does it differently than Windows.
After the edit, you have to either close the shell and re-open it or use
Code:
source ~/.bashrc
to "re-read" it into the current shell session.

I know what the purpose of the path is on every OS.
but since "No such file or directory" doesn't say jack-all about what generated the message...I asked you to test the full path to the script.
Is bash spewing "No such file or directory" or is the script?

Seems export PATH=$PATH:/root/Scripts/ should be enough.

Last edited by Habitual; 02-08-2016 at 05:40 PM.
 
Old 02-08-2016, 06:22 PM   #5
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Full path to script

Quote:
# dirs
~
# /root/Scripts/./Findit.sh
Error!! No filename given. Searches ONLY current drive !!
 
Old 02-08-2016, 06:47 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
does /root/Scripts/./Findit.sh take parameters?

Last edited by Habitual; 02-08-2016 at 06:49 PM.
 
Old 02-08-2016, 06:50 PM   #7
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Yes.
Quote:
[ ! $1 ] && {
echo -e "Error!! No filename given. Searches ONLY current drive !!"; exit 1; } || echo -e "Searching for $1"
find -name $1
Can I make an alias that puts /root/Scripts/ in "front of" the script I want to run ?

Last edited by Fixit7; 02-08-2016 at 06:53 PM.
 
Old 02-09-2016, 06:20 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
export PATH=/root/Scripts/:$PATH
 
Old 02-09-2016, 05:24 PM   #9
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I have that in .bashrc but still get

Quote:
# ./Findit.sh
bash: ./Findit.sh: No such file or directory
 
Old 02-09-2016, 05:28 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
don't use the .
Code:
Findit.sh

Last edited by Habitual; 02-09-2016 at 06:46 PM.
 
Old 02-10-2016, 08:34 AM   #11
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Couple of possible issues here, and I think this probably should be in the Linux Software, Linux General, or Programming forums instead of Non-Nix General.

You've place a script in /root/Scripts.

Who owns that directory and what permissions does it allow?

Findit.sh should be executable permissions, but also should be executable permissions for the user which is attempting to run the script.

The two or three things which need to be satisfied are: (EDIT: OK 5 or 6! )
  1. The user attempting to execute any script or binary, must be able to "see" via permissions, the directory where the script or binary resides
  2. The permissions for the script or binary must be executable for the user type which is attempting to run it
  3. The user which is attempting to run it should have the directory where the binary or script resides, as part of their path, and they must log out and log back in as the best way to ensure that the update to the PATH is taken care of, or use one of the various source calls or re-run .bashrc. I say best to just create a new terminal window and verify that PATH now contains what you intend it to contain.
  4. As pointed out, if there are arguments for a script or binary, and it doesn't tell you this, but instead encounters and error as shown, pretty bad script writing, but for a script, one can also turn on debugging and see if the problem lies within the first lines of the script versus if the problem lies in running the script.
  5. You can stage this differently by copying the script locally and verify that when you are the owner and it's in your home directory, or "." (your local directory) that you can run the script successfully, all before you place it in a common system location, of which /root really isn't common for all users
  6. I personally have "." in my path variable, that's just me, I'm sure there may be reasons why someone wouldn't do that, but I've like done it since the Unix days ...
 
Old 02-10-2016, 12:37 PM   #12
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Habitual has it right -the OP is using the relative dir './' to call the program. Leave off the './' before the program name so that the shell searches for the object in the PATH.
 
Old 02-10-2016, 04:08 PM   #13
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Quote:
Originally Posted by gnashley View Post
Habitual has it right -the OP is using the relative dir './' to call the program. Leave off the './' before the program name so that the shell searches for the object in the PATH.
You and gnashley get the gold star.

Do not need ./ and less typing too.

Rtmistler,

All flavors of Puppy run as root.

This makes some Linux users cringe, but it's ok if you are safe and cautious.

Last edited by Fixit7; 02-10-2016 at 04:10 PM.
 
Old 02-10-2016, 04:14 PM   #14
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
woot.
 
Old 02-10-2016, 08:32 PM   #15
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Code:
PATH=$PATH:/path/to/dir1; export PATH

Last edited by BW-userx; 02-10-2016 at 08:37 PM.
 
  


Reply



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] extract directory name from path in script farmkid Linux - Newbie 6 04-13-2012 11:32 AM
[SOLVED] Shell Script - Use variable in a for loop with directory path Tech109 Linux - General 2 01-19-2011 10:22 AM
Script cannot find directory path mike2008 Linux - Newbie 7 04-29-2009 12:12 PM
Shell script help: How to pass a directory path to the script? dv502 Programming 13 09-10-2008 03:07 AM
Discovering Script Directory Path WayneK Programming 9 07-14-2008 09:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:08 AM.

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
Open Source Consulting | Domain Registration