自定义 shell 脚本无法运行

自定义 shell 脚本无法运行

我已经写了一个 shell 脚本,显示脚本

我的脚本

#!/bin/bash
ssh -t proxy@PROXY -p 22022 "ssh me@REMOATE_MACHINE -p 22022"

我把脚本放到/opt/scripts/myscript.shchmod u+x myscript.sh。之后我添加export PATH=$PATH:/opt/scripts/myscript.sh.bashrc

然后source .bashrc,但是当我输入时myscript.sh,终端返回myscript.sh: command not found

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在里面PATH

我该如何修复这个问题?

答案1

您不应将脚本本身添加到$PATH。相反,您应该将包含脚本的目录添加到$PATH

export PATH=$PATH:/opt/scripts

答案2

不应该是/opt/scripts/myscript.sh。应该是/opt/scripts。它被/opt/scripts/myscript.sh视为目录并使用其中的所有文件,而不是其本身。这可以通过以下命令实现;

PATH=$PATH:/opt/scripts
export PATH

相关内容