我有一个脚本,使用sh shell。我在使用source命令的行中得到一个错误。它似乎源不包括在我的sh shell。

如果我显式地尝试从shell运行source,我得到:

sh: 1: source: not found

我是否应该安装“source”?我的sh版本是否错误?


当前回答

当我试图从#Jenkins执行shell调用源命令时,我遇到了这个错误。

源profile.txt 或 源profile.properties

替换源命令是使用,

。。/ profile.txt 或 。。/ profile.properties

注意:两个点之间有一个空格。

其他回答

如果你不能把脚本改成“。”而不是“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

在Bourne shell(sh)中,使用。命令获取文件的源

. filename

在某些操作系统/环境(Mac OS, Travis-CI, Ubuntu,至少),这必须是:

. ./filename

(以下是Adrien Joly的评论)

$ls -l `which sh`
/bin/sh -> dash

$sudo dpkg-reconfigure dash #Select "no" when you're asked
[...]

$ls -l `which sh`
/bin/sh -> bash

那就好了

源代码是内置的bashism。简单地写成。代替。

e.g.

. $FILE

# OR you may need to use a relative path (such as in an `npm` script):

. ./$FILE

https://wiki.ubuntu.com/DashAsBinSh#source

这可能会帮助你,我得到这个错误,因为我试图用命令. .profile重新加载我的.profile,它有一个语法错误