可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a linux script which uses sh shell. I hit an error in a line which uses a "source" command. Basically, it seems "source" is not included in my sh shell. If I enter sh and enter source I get:
sh: 1: source: not found
Should I explicitly install "source"? Do I have a wrong version of sh shell?
回答1:
/bin/sh
is usually some other shell trying to mimic The Shell. Many distributions use /bin/bash
for sh
, it supports source
. On Ubuntu, though, /bin/dash
is used which does not support source
. If you cannot edit the script, try to change the shell which runs it.
回答2:
In Bourne shell(sh), use the . command to source a file
. filename
回答3:
$ls -l `which sh` /bin/sh -> dash $sudo dpkg-reconfigure dash #Select "no" when you're asked [...] $ls -l `which sh` /bin/sh -> bash
Then it will be OK
回答4:
The source
command is built into some shells. If you have a script, it should specify what shell to use on the first line, such as:
#!/bin/bash
回答5:
The source
builtin is a bashism. Write this simply as .
instead.
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
回答6:
This problem happens because jenkins Execute Shell runs the script via its /bin/sh
Consequently, /bin/sh does not know "source"
You just need to add the below line at the top of your Execute Shell in jenkins
#!/bin/bash
回答7:
Bourne shell (sh) uses PATH to locate in source
. If the file you are trying to source is not in your path, you get the error 'file not found'.
Try:
source ./
回答8:
I found in a gnu Makefile on Ubuntu, (where /bin/sh -> bash)
I needed to use the . command, as well as specify the target script with a ./ prefix (see example below)
source did not work in this instance, not sure why since it should be calling /bin/bash..
My SHELL environment variable is also set to /bin/bash
test: $(shell . ./my_script)
Note this sample does not include the tab character; had to format for stack exchange.
回答9:
source is a bash built-in command so to execute source command, you can log in as Root.
sudo -s source ./filename.sh
回答10:
This may help you, I was getting this error because I was trying to reload my .profile
with the command . .profile
and it had a syntax error