I've been struggling for the past two hours on this simple example :
I have this line:
python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'
Which gives:
Loaded plugins: product-id
{'arch': 'ia32e',
'basearch': 'x86_64',
'releasever': '7Server',
'uuid': 'd68993fd-059a-4753-a7ab-1c4a601d206f',
'yum8': 'rhel',
'yum9': '7.1'}
And now, I would just like to get the line with the 'releasever'.
Directly on my Linux, there is no problem:
$ python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)' | grep releasever
'releasever': '7Server',
I have the answer I am looking for.
But when it comes to put it in a script, I am so helpless.
Currently, I have:
#!/bin/ksh
check="$(python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)')"
echo "${check}"
# The echo works as expected. But now, I would like to do a grep on that variable:
check2=${check}|grep releasever
echo "${check2}"
And the result is empty.
I've tried a lot of different things, like brackets, parentheses, quote, double quote, all-in-one command, but I can't get what I want. I don't know what's happening behind that code, which is very simple. But still…
Can someone help me?