linux - sh脚本找不到变量

标签 linux sh

我正在学习如何运行反向 ssh 隧道的教程,该教程位于 http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunneling。我遇到的问题是当我运行 tunneling.sh 脚本时:

#!/bin/sh
a=`ps -ef | grep 19999 | grep -v grep`
if [ ! "$a" ]; then
    ssh -fN -R 19999:localhost:22 <middle-usename>@<middle-hostname>
fi

我收到此错误:

tunnel2.sh: 2: tunnel2.sh: a: not found

编辑:

我将 shebang 更改为 #!/bin/bash

现在我得到这个错误:

tunnel2.sh: 2: tunnel2.sh: pi: not found

最佳答案

如果您要使用 bash 功能,请不要在您的“shebang”行中指定 #!/bin/sh。如果你想要 bash,请要求 bash。

关于linux - sh脚本找不到变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13709315/

相关文章:

linux - 从哪里获得完整的联机帮助页

python - 需要使用 python 子进程模块来导航 Linux 目录的帮助

linux - bssh 自动在两个 linux 服务器之间传输文件

linux - 如何安全地在Linux命令行上解压缩文件

bash - 为什么正确的 shell 脚本会给出包装/截断/损坏的错误消息?

Ruby 执行卡在 system() 行

c - 打印文件传输额外的行

linux - 如何一次读取一行多行变量?

linux - 在重音符内执行时 sed 奇怪的行为 - `

linux - 将 3 个功能合并为一个