(bash) how to list all variables?
Hi,
how can I list all variables that are sourced from another file? Code:
#!/bin/bash |
/tmp/variables looks like this:
A=1 B=2 C=3 #D=5 |
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. Anyone else? |
ddi you want all the variables sourced from a particular file?
if you wanted all the variables in use then you can use set |
And maybe you could store the output of set, source the file, store another output of set, then
compare the outputs |
Quote:
Code:
#!/bin/bash or this seems to work as well (and I think this is what you were talking about): Code:
#!/bin/bash Thanks! |
Double post.
|
sdiff can help to filter the "unnecessary" stuff out:
Code:
#!/bin/bash |
dustu76:
Nice!! (= |
Quote:
sdiff seems to clean most of the "useless" variables away. Thanks! |
set | grep -f variables-in-use
this works, but no blanks allowed in the data file DATA Code:
billym.primadtpdev>cat ~/1 SCRIPT Code:
Code:
billym.primadtpdev>ksh ~/2 |
Quote:
Code:
set>/tmp/variables.0 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.) |
All times are GMT -5. The time now is 01:52 AM. |