ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I think that no matter how you play it, you're going to have to do some work. AFAIK, there is no easy solution. If your variable file will always look like your example, you can write the bash to look for lines that don't start with # and which contain an equals sign (=) and strip off the equals and anything after it.. that would at least provide you with the variables that have been assigned.
That's about the best of which I can think at the moment.
Distribution: Red Hat (8.0, RHEL5,6), CentOS, SuSE (10.x, 11.x, 12.2, 13.2), Solaris (8-10), Tru64, MacOS, Raspian
Originally posted by keefaz And maybe you could store the output of set, source the file, store another output of set, then
compare the outputs
That's pretty much the way I'd handle this.
echo "file-containing-variable-defs defined the following:"
cat /tmp/variables.0 /tmp/variables.1 | sort | unit -u
I suppose env would work just as well in the above (as some others suggested). If you only want the variable names and not their values, just pipe the result from "uniq" into "cut -d= -f1"
I wrote a shell function a long time ago that did something like (I think) Duudson was looking for. It was to allow someone to display the contents of a config file that was being used in a script. It read the config file a line at a time rather than sourcing it and only displayed the non-comment lines before defining the variable. (I didn't want to deal with temp files at the time even though sourcing the file would have been faster.)