anusngh
anusngh

Reputation: 97

What is the significance of . $1 in the below script

Could you please help me to understand the significance of . $1 in the script below.

# source the config file after checking for a valid file
if [ -f $1 ]
then
    echo "File path " $1
else
    echo "Not a valid filename"
    exit 1
fi
curr_dir=$( cd "$( dirname "$0" )" && pwd )
country='AU'

. $1
echo "========Printing config properties====="
cat $1

Upvotes: 0

Views: 2287

Answers (2)

varun
varun

Reputation: 1523

$1 is the first parameter to shell script.

. $1

will execute the bash script file if $1 contains the name of that file. If it doesnt contain the name of a bash script then appropriate error will be shown.

for example :

  $ i=test.sh
  $ . $i 

will execute the file test.sh in the current directory

Upvotes: 1

Chris Maes
Chris Maes

Reputation: 37782

$1 is the first argument. The script supposes the first argument will be a file (whence the [ -f $1]).

suppose in the file variables and/or functions are declared, running

. $1

will make those variables and functions available for use in your script. You are sort of "including" the file $1 in you script.

Upvotes: 2

Related Questions