Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able to source a property file in shell script

Tags:

shell

unix

I tried the following two ways to source the property file

#!/bin/sh
. import.properties
echo $USER_ID
echo $INPUT_FILE

It says :

./test.sh[3]: import.properties:  not found

when tried using source import.properties it gave the message as:

./test.sh[3]: source:  not found.

I am very new to the scripting and env. Please let me know what I am missing here?

like image 577
beetri Avatar asked Jan 19 '12 00:01

beetri


1 Answers

To be found by the dot . command, the file must be readable (not necessarily executable) and on your PATH (and to be safely usable, it must contain shell script).

If the file is in your current directory and . (the directory, not the command) is not on your PATH, you can use:

. ./import.properties

Otherwise, you need to specify the absolute name of the file, or relative name of the file, or move the file to a convenient directory on your PATH.

The alternative notation, source import.properties fails because you are not in the C Shell, and because you are not using Bash. The source command in the C Shell is the analogue of the dot command in the Bourne shell. Bash allows it as a synonym for the dot command (or the dot command as a synonym for source). Since source was not found, we can safely assume your shell does not support it as a built-in.

like image 119
Jonathan Leffler Avatar answered Nov 01 '22 08:11

Jonathan Leffler