我有一个脚本,使用sh shell。我在使用source命令的行中得到一个错误。它似乎源不包括在我的sh shell。
如果我显式地尝试从shell运行source,我得到:
sh: 1: source: not found
我是否应该安装“source”?我的sh版本是否错误?
我有一个脚本,使用sh shell。我在使用source命令的行中得到一个错误。它似乎源不包括在我的sh shell。
如果我显式地尝试从shell运行source,我得到:
sh: 1: source: not found
我是否应该安装“source”?我的sh版本是否错误?
当前回答
Bourne shell (sh)使用PATH定位源<文件>。如果你试图获取的文件不在你的路径中,你会得到错误“文件未找到”。
试一试:
source ./<filename>
其他回答
$ls -l `which sh`
/bin/sh -> dash
$sudo dpkg-reconfigure dash #Select "no" when you're asked
[...]
$ls -l `which sh`
/bin/sh -> bash
那就好了
发生此问题是因为jenkins Execute Shell通过其/bin/sh运行脚本
因此,/bin/sh不知道“源”
您只需要在jenkins中Execute Shell的顶部添加下面的行
#!/bin/bash
Bourne shell (sh)使用PATH定位源<文件>。如果你试图获取的文件不在你的路径中,你会得到错误“文件未找到”。
试一试:
source ./<filename>
source是bash内置命令,因此要执行source命令,您可以以Root用户登录。
sudo - s 源。/ filename.sh
我在Ubuntu上的gnu Makefile中找到了(其中/bin/sh -> bash)
我需要用。命令,并使用./前缀指定目标脚本(参见下面的示例)
源没有工作在这种情况下,不确定为什么,因为它应该调用/bin/ bash_. .
我的SHELL环境变量也设置为/bin/bash
test:
$(shell . ./my_script)
注意,这个示例不包括制表符;必须格式化堆栈交换。