0

Update: Included a lot more relevant information, thank you for suggesting including this!

I am very new to Linux and I am trying to run scripts that someone else created. I recently learned about the $PATH variable, and realized that I need to add my scripts folder to my $PATH variable in order to make it callable from anywhere on the terminal. However, even when I add the folder containing my script to the $PATH variable, the script inside is not being recognized.

I have edited my bashrc file in a text editor, at the bottom to include:

#Modify $PATH
export PATH="/home/eli/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

My script is located in /home/eli/bin, if I don't specify the entire path, the script will not run despite this bin being in my $PATH variable.

So, here's my $PATH variable:

(base) eli@eli-XPS-13-7390-2-in-1:~$ echo $PATH
/home/eli/miniconda3/bin:/home/eli/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Here are my script permissions:

(base) eli@eli-XPS-13-7390-2-in-1:~$ ls -al ~/bin/trim2bRAD_2barcodes_noAdap.pl
-rwxr-xr-x 1 eli eli 3064 May 19  2018 /home/eli/bin/trim2bRAD_2barcodes_noAdap.pl

Here is the output when I try to run the script without being in the directory or specifying the exact path to the file:

(base) eli@eli-XPS-13-7390-2-in-1:~$ ./trim2bRAD_2barcodes_noAdap.pl
bash: ./trim2bRAD_2barcodes_noAdap.pl: No such file or directory
5
  • 1
    Try the export statement without the double quotes. Commented Dec 14, 2020 at 19:00
  • 1
    ls $HOME/Scripts/2bRAD_Edwards_Lab ? "the directory is not found" - please post the entire output. Bash couldn't have said that - it ignores PATHs which don't exist. Commented Dec 14, 2020 at 19:20
  • Please update the question with the exact command you run, the exact output you get and the output of some command to see this file, its permissions etc, like ls -al path/to/the/scripts/script_name.sh.
    – thanasisp
    Commented Dec 14, 2020 at 19:37
  • Note: This way you don't keep any previous PATH values. The usual way is to extend the existing PATH, whatever it is.
    – thanasisp
    Commented Dec 14, 2020 at 19:42
  • 1
    Thank you @thanasisp and Artem, I just added more information! I don't think I asked that clearly enough. Commented Dec 15, 2020 at 21:11

1 Answer 1

2

When you want the shell to do a search for an executable in the directories listed in your $PATH variable, don't specify a path for the executable on the command line.

So, don't do

./trim2bRAD_2barcodes_noAdap.pl

as this does not make the shell look in $PATH at all (you gave the explicit path ./ for the executable).

Instead, use just

trim2bRAD_2barcodes_noAdap.pl

Also, when you add /home/eli/bin to the start of your $PATH, you can say

PATH=$HOME/bin:$PATH

assuming $HOME will expand to /home/eli. I.e., there is no need to list all directories in $PATH unless you want to set the variable to that very specific list of directories and/or don't trust the system to having given you a sane default. You also do not need to export PATH as it is already an environment variable.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .