So, I have this command I want to execute and then capture the output of:
cat /etc/sysconfig/network-scripts/ifcfgxxx | grep IPADDR | sed -E -e 's/[[:blank:]]+/\n/g'"
However, in my script, the path is a variable:
mypath="/etc/sysconfig/network-scripts/ifcfgxxx"
So my command looks like this:
cat ${mypath} | grep IPADDR | sed -E -e 's/[[:blank:]]+/\n/g'"
When I put this into my script like this, it works:
mypath="/etc/sysconfig/network-scripts/ifcfgxxx"
output="$(cat ${mypath} | grep IPADDR | sed -E -e 's/[[:blank:]]+/\n/g')"
echo ${output}
This is what I get:
IPADDR=192.168.1.3
IPADDR1=192.168.1.4
IPADDR2=192.168.1.5
IPADDR3=192.168.1.6
However, when I put this into my script, it does not work:
mypath="/etc/sysconfig/network-scripts/ifcfgxxx"
mycommand="cat ${mypath} | grep IPADDR | sed -E -e 's/[[:blank:]]+/\n/g'"
output="$(${mycommand})"
echo ${output}
I get a bunch of errors:
cat: |: No such file or directory
cat: grep: No such file or directory
cat: IPADDR: No such file or directory
cat: |: No such file or directory
cat: sed: No such file or directory
cat: 's/[[:blank:]]+/\n/g': No such file or directory
Any idea how I can do this with my command being a variable?
Thanks