I have a conf file content like below.



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


key="name"      #key as variable
value="pswd"    #value as variable
  • 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


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)

  • 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 .