我有一个脚本,使用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版本是否错误?
当前回答
这可能会帮助你,我得到这个错误,因为我试图用命令. .profile重新加载我的.profile,它有一个语法错误
其他回答
你有两个选择,从纯shell切换到bash,启用bash功能,包括source。 https://superuser.com/questions/1220159/bash-prompt-variables-not-working/1764353#1764353
或者使用。而不是用这种形式的源
. ~ / .your_file_name
例如
我们走吧。~ / . bashrc
请考虑在多特和蒂尔达之间留个位置。Tilda指的是主目录,如果你的文件位于主目录上方的某个位置,请使用/中的绝对地址
这可能会帮助你,我得到这个错误,因为我试图用命令. .profile重新加载我的.profile,它有一个语法错误
$ls -l `which sh`
/bin/sh -> dash
$sudo dpkg-reconfigure dash #Select "no" when you're asked
[...]
$ls -l `which sh`
/bin/sh -> bash
那就好了
/bin/sh通常是试图模仿shell的其他shell。许多发行版使用/bin/bash作为sh,它支持source。但是在Ubuntu上,使用的是不支持source的/bin/dash。大多数shell使用。而不是来源。如果无法编辑脚本,请尝试更改运行脚本的shell。
Bourne shell (sh)使用PATH定位源<文件>。如果你试图获取的文件不在你的路径中,你会得到错误“文件未找到”。
试一试:
source ./<filename>