4

I have a conf file content like below.

file.conf:

key="name"
value="pswd"

Now I want write a script to having two variable like above

script.sh

key="name"      #key as variable
value="pswd"    #value as variable
1
  • 2
    . /path/to/file.conf (if the file is not under your control, then you'll want to sanitize it though) Commented Dec 5, 2014 at 10:58

1 Answer 1

8

Just source the file inside the script:

. /path/to/file.conf

But notice, the .conf file must have a valid sh syntax, because . interprets the content of the given file as sh code.

(. is the POSIX/portable command for Bourne-like shells. For (t)csh shells, use source instead. bash, ksh and zsh support both though with subtle differences for some)

2
  • It's working for bash. I mainly looking for shell script (#!/bin/sh). It is saying source not found
    – gangadhars
    Commented Dec 5, 2014 at 11:10
  • Thanks, I figured it out. For bin/sh, we just need to source with a .
    – gangadhars
    Commented Dec 5, 2014 at 11:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .