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: Clark WANG
Subject: Re: [Help-bash] Sourcing only valid variables from a script configuration file
Date: Mon, 2 Jul 2012 16:48:38 +0800

On Mon, Jul 2, 2012 at 4:15 PM, Jesse Molina <address@hidden> wrote:

Hello everyone

I am trying to do something that bash doesn't seem to be very good at. I'll admit right now that the best advice for myself would be to re-write my script in python or perl.  However, I really wanted to do this in bash for educational purposes.  Thus, I have created a monster.

I have a script which reads a configuration file, which is simply made up of comments and variable assignments.

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

In this configuration file, the variables are known and expected.  If an expected variable is missing or invalid, we exit with an error.  If addition non-variable or comment data is in the configuration file, we should also exit with an error.

I will probably end up writing a function to validate the stat() on the file, grep for anything invalid, make sure there are no command substitution or similar nonsense within the valid variables, and the like.

I'm not a perl or python expert but how can you easily do such kind of things with perl or python? By using some conf file parsing modules?

Does anyone have any helpful advice for me on this subject beyond what I already know here?





reply via email to

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