Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

source: not found in shell script? [duplicate]

I want to activate a virtual env in shell script, so I write a simple script as follow:

#!/bin/bash

source ~/env/lib/bin/activate
#nohup python mock_run.py
#echo $! > save_pid.txt

I start the script with sh start.sh, but I got error as follow:

start.sh: 3: start.sh: source: not found

I run source ~/env/lib/bin/activate is ok, so why can not in shell script?

like image 732
roger Avatar asked Dec 11 '22 20:12

roger


1 Answers

Note that the shebang line:

#!/bin/bash

is not in effect when you invoke the script with

sh script.sh

The shebang is in effect only if you call the script directly, like a binary.


You need to either:

chmod +x script.sh
./script.sh

to make the shebang line working, or call it explicitly with bash:

bash script.sh
like image 137
hek2mgl Avatar answered Dec 30 '22 18:12

hek2mgl