Müller
Müller

Reputation: 1023

source command not detecting the file in Linux bash

Here is an excerpt from my Bash script

#!/bin/sh
# Check SPEED parameter validity
if [ "$4" = "SPEED" ] 
then
    source ${SIM_DIR}/setEnv.sh speed
elif [ "$4" = "NORMAL" ]
then
    pushd ${SIM_DIR}/scripts
    source setEnv
else
    ERROR "Invalid SPEED|NORMAL parameter ($4)."
    exit 1
fi

In command line, I am giving the option as NORMAL when I run the script. There is no file called setEnv.sh in the ${SIM_DIR}/scripts location. There is however a file called setEnv and its first line is #!/bin/bash -x. I get the following error:

line 176: source: setEnv: file not found

Could anybody kindly point out what is wrong with my script?

Upvotes: 0

Views: 784

Answers (1)

chepner
chepner

Reputation: 532418

source uses PATH lookups to find names that do not contain slashes, and your PATH (correctly) does not contain ., so the current directory is not searched for setEnv. Use source ./setEnv.

The shebang line is ignored by source.

Upvotes: 3

Related Questions