help-bash
[Top][All Lists]
Advanced

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

[Help-bash] Sourcing only valid variables from a script configuration fi


From: Jesse Molina
Subject: [Help-bash] Sourcing only valid variables from a script configuration file
Date: Mon, 02 Jul 2012 01:15:59 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120604 Firefox/13.0 SeaMonkey/2.10


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.

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



FYI I spent an hour or two googling around and came up with the following articles. Mostly, it was confirmed that there isn't a built-in to make this easy, which disappointed me:

http://lcorg.blogspot.com/2010/06/using-configuration-files-with-shell.html

http://stackoverflow.com/questions/4434797/read-a-config-file-in-bash-without-using-source

http://wiki.bash-hackers.org/howto/conffile

https://bbs.archlinux.org/viewtopic.php?id=39451

http://stackoverflow.com/questions/5983558/reading-a-config-file-from-a-shell-script



--
# Jesse Molina
# Mail = address@hidden
# Cell = 1-602-323-7608






reply via email to

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