我有一个脚本,使用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版本是否错误?
当前回答
发生此问题是因为jenkins Execute Shell通过其/bin/sh运行脚本
因此,/bin/sh不知道“源”
您只需要在jenkins中Execute Shell的顶部添加下面的行
#!/bin/bash
其他回答
你有两个选择,从纯shell切换到bash,启用bash功能,包括source。 https://superuser.com/questions/1220159/bash-prompt-variables-not-working/1764353#1764353
或者使用。而不是用这种形式的源
. ~ / .your_file_name
例如
我们走吧。~ / . bashrc
请考虑在多特和蒂尔达之间留个位置。Tilda指的是主目录,如果你的文件位于主目录上方的某个位置,请使用/中的绝对地址
source命令内置于某些shell中。如果你有一个脚本,它应该在第一行指定使用什么shell,例如:
#!/bin/bash
当我试图从#Jenkins执行shell调用源命令时,我遇到了这个错误。
源profile.txt 或 源profile.properties
替换源命令是使用,
。。/ profile.txt 或 。。/ profile.properties
注意:两个点之间有一个空格。
发生此问题是因为jenkins Execute Shell通过其/bin/sh运行脚本
因此,/bin/sh不知道“源”
您只需要在jenkins中Execute Shell的顶部添加下面的行
#!/bin/bash
如果你不能把脚本改成“。”而不是“source”,把“sh”的链接改成“bash”而不是“dash”:
# which sh
/usr/bin/sh
# which bash
/usr/bin/bash
# ls -la /usr/bin/sh
lrwxrwxrwx 1 root root 4 Oct 5 15:55 /usr/bin/sh -> dash
# ls -sf /usr/bin/bash /usr/bin/sh
# ls -la /usr/bin/sh
lrwxrwxrwx 1 root root 4 Feb 6 09:18 /usr/bin/sh -> bash