0

I have wrote a shell script, show the script

myscript.sh

#!/bin/bash
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

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin:/opt/scripts/myscript.sh:/usr/lib/jvm/java-8-oracle/bin:/bin:/bin:/opt/hadoop-2.6.4/bin:/opt/hadoop-2.6.4/sbin:/opt/hive-2.0.0-bin/bin

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

How should I fix the problem?

1

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
1

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;

PATH=$PATH:/opt/scripts
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.