Source command not found in sh shell

I have a script that uses sh shell. I get an error on a line that uses the source command. source doesn't seem to be part of my sh shell.

If I explicitly try to run source from the shell, I get:

 sh: 1: source: not found 

Should I somehow establish the "source"? I have the wrong version of sh ?

+96
linux bash shell sh ubuntu
Dec 04 '12 at 12:01
source share
11 answers

/bin/sh is usually another shell trying to mimic a shell. Many distributions use /bin/bash for sh , it supports source . Ubuntu, however, uses /bin/dash which does not support source . Most shells use . instead of source . If you cannot edit the script, try changing the shell that runs it.

+83
Dec 04
source share

In Bourne shell (sh) use. command for file source

 . filename 
+92
Dec 04
source share
 $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

+41
Jan 07 '14 at 6:16
source share

The embedded source is bashism. Write it just how . instead.

eg

 . $FILE # OR you may need to use a relative path (such as in an 'npm' script): . ./$FILE 

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

+15
Jul 13 '17 at 19:38
source share

The source command is built into some shells. If you have a script, it should indicate which shell to use in the first line, for example:

 #!/bin/bash 
+7
Dec 04
source share

This problem arises because jenkins Execute Shell runs the script through its / bin / sh

Therefore, / bin / sh does not know the "source"

You just need to add the line below at the top of your jenkins command line

 #!/bin/bash 
+5
Jan 25 '16 at 9:06
source share

I found in the gnu Makefile on Ubuntu (where / bin / sh -> bash)

I needed to use. As well as specify the target script with the prefix ./ (see example below)

the source did not work in this case, not sure why, since it should call / bin / bash ..

My SHELL environment variable is also set to / bin / bash

 test: $(shell . ./my_script) 

Note that this pattern does not contain a tab character; had to format for sharing stacks.

0
07 Oct '15 at 18:28
source share

source is a built-in bash command, so you can log in as Root to execute the source command.

sudo -s source ./filename.sh

0
Aug 15 '17 at 8:42 on
source share

I encountered this error when I tried to invoke the original command from the #Jenkins shell.

source profile.txt or source profile.properties

The replacement for the original team is to use,

../profile.txt ../profile.txt or ../profile.properties ../profile.properties

Note. There is a space (.) Between the two points

0
Mar 27 '19 at 17:04
source share

Bourne shell (sh) uses PATH to search in source <file> . If the file you are trying to use is not in your path, you will receive an error file that was not found.

Try:

 source ./<filename> 
-one
Oct 08 '14 at 8:25
source share

It may help you, I got this error because I tried to reload my .profile with the command . .profile . .profile and had a syntax error

-2
Nov 11 '16 at
source share



All Articles