Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source command not found in sh shell

Tags:

bash

shell

sh

People also ask

What is source command in shell?

In Linux systems, source is a built-in shell command that reads and executes the file content in the current shell. These files usually contain a list of commands delivered to the TCL interpreter to be read and run.

How do you source a file in shell?

A file is sourced in two ways. One is either writting as source <fileName> or other is writting as . ./<filename> in the command line. When a file is sourced, the code lines are executed as if they were printed on the command line.

Where is source located in Linux?

Shortened as '. ', the source command is mostly used in the context of shells run in terminal windows. Note that when arguments are provided, they are set as positional parameters for the script specified. Note : the source documentation is located inside the bash documentation.

How do I run a source in bash?

Type the command "help source" in your shell. You will get output like this: source: source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell.


/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. Most shells use . instead of source. If you cannot edit the script, try to change the shell which runs it.


In Bourne shell(sh), use the . command to source a file

. filename

In certain OS's/environments (Mac OS, Travis-CI, Ubuntu, at least) this must be:

. ./filename

(Credit to Adrien Joly's comment below)


$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


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


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

I faced this error while i was trying to call source command from #Jenkins execute shell.

source profile.txt or source profile.properties

Replacement for source command is to use,

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

Note: There is a space between the two dots(.)