help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Sourcing only valid variables from a script configuratio


From: Greg Wooledge
Subject: Re: [Help-bash] Sourcing only valid variables from a script configuration file
Date: Mon, 2 Jul 2012 08:13:50 -0400
User-agent: Mutt/1.4.2.3i

On Mon, Jul 02, 2012 at 01:15:59AM -0700, Jesse Molina wrote:
> 'source' is the obvious correct command to bring this configuration file 
> into the script.  However, I want input validation and other protections 
> against commands and other non-expected data from being in the 
> configuration file.

while IFS== read -r var value; do
  [[ $var = \#* ]] && continue
  printf -v "$var" %s "$value"
done

If you want additional error checking, redirect 2>/dev/null on the printf
and check its exit status.  It should fail when the left hand side (var)
is not a valid identifier.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]