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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityJust 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)
#!/bin/sh
). It is saying source not found
Dec 5, 2014 at 11:10
bin/sh
, we just need to source
with a .
Dec 5, 2014 at 11:24
. /path/to/file.conf
(if the file is not under your control, then you'll want to sanitize it though)