I have wrote a shell script, show the script


ssh -t proxy@PROXY -p 22022 "ssh me@REMOATE_MACHINE -p 22022"

And I put the script to /opt/scripts/myscript.sh, and chmod u+x myscript.sh. After that I added export PATH=$PATH:/opt/scripts/myscript.sh in .bashrc.

And then source .bashrc, but when I type myscript.sh, the terminal returned myscript.sh: command not found

And echo $PATH


/opt/scripts/myscript.sh is in the PATH

How should I fix the problem?


You should not add the script itself to $PATH. Instead, you should add the directory containing the script to $PATH:

export PATH=$PATH:/opt/scripts

It should not be /opt/scripts/myscript.sh. It should be /opt/scripts. It is treating /opt/scripts/myscript.sh as a directory and using all the files in it, not itself. This can be achieved by the following commands;

export PATH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.