错误导入具有功能的文件会导致找不到命令吗?
Can wrong import of file with functions cause command not found?
我有一个主脚本 1,我在其中调用脚本 2 中的函数,我使用 source
导入它。当调用 script2 中的函数时,它会调用 script2 中的另一个函数,但命令出错并显示“找不到 X 命令”。是我导入的文件有误还是有其他问题?
script1.sh:
#!/bin/bash
source ./script2.sh
get
# the script crashes due to jq command not found
script2.sh:
#!/bin/bash
get(){
jq ...
echo "So far so good, command goes through."
dosomething
}
dosomething(){
echo "Here the command fails with jq command not found :("
jq ...
}
我没有注意到我在某些时候使用了 PATH 变量,这造成了麻烦。感谢您指出 Gordon Davisson。
我有一个主脚本 1,我在其中调用脚本 2 中的函数,我使用 source
导入它。当调用 script2 中的函数时,它会调用 script2 中的另一个函数,但命令出错并显示“找不到 X 命令”。是我导入的文件有误还是有其他问题?
script1.sh:
#!/bin/bash
source ./script2.sh
get
# the script crashes due to jq command not found
script2.sh:
#!/bin/bash
get(){
jq ...
echo "So far so good, command goes through."
dosomething
}
dosomething(){
echo "Here the command fails with jq command not found :("
jq ...
}
我没有注意到我在某些时候使用了 PATH 变量,这造成了麻烦。感谢您指出 Gordon Davisson。