LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script directory in path (https://www.linuxquestions.org/questions/linux-newbie-8/script-directory-in-path-4175571740/)

Fixit7 02-08-2016 04:21 PM

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/

Habitual 02-08-2016 04:35 PM

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

Fixit7 02-08-2016 05:26 PM

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.

Habitual 02-08-2016 05:34 PM

Quote:

Originally Posted by Fixit7 (Post 5497278)
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.

Fixit7 02-08-2016 06:22 PM

Full path to script

Quote:

# dirs
~
# /root/Scripts/./Findit.sh
Error!! No filename given. Searches ONLY current drive !!

Habitual 02-08-2016 06:47 PM

does /root/Scripts/./Findit.sh take parameters?

Fixit7 02-08-2016 06:50 PM

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 ?

gnashley 02-09-2016 06:20 AM

export PATH=/root/Scripts/:$PATH

Fixit7 02-09-2016 05:24 PM

I have that in .bashrc but still get

Quote:

# ./Findit.sh
bash: ./Findit.sh: No such file or directory

Habitual 02-09-2016 05:28 PM

don't use the .
Code:

Findit.sh

rtmistler 02-10-2016 08:34 AM

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 ...

gnashley 02-10-2016 12:37 PM

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.

Fixit7 02-10-2016 04:08 PM

Quote:

Originally Posted by gnashley (Post 5498203)
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.

Habitual 02-10-2016 04:14 PM

woot.

BW-userx 02-10-2016 08:32 PM

Code:

PATH=$PATH:/path/to/dir1; export PATH


All times are GMT -5. The time now is 06:32 AM.