Based on the values in the second column, I need to run another command on these values.
[root@box ~]# for i in $(openstack server list --all -c ID -f value); do openstack server show $i -f value -c name -c project_id | xargs printf '%-60s %s\n'; done
cf1-0 ebf0f23f424c4417afd3e7bbf4e3900f
sf1-3 ebf0f23f424c4417afd3e7bbf4e3900f
sf1-2 ebf0f23f424c4417afd3e7bbf4e3900f
sf1-0 ebf0f23f424c4417afd3e7bbf4e3900f
Here's an example of what I'm trying to do.
[root@box ~]# for i in $(openstack server list --all -c ID -f value); do openstack server show $i -f value -c name -c project_id | xargs printf "%-60s eval(openstack project show %s -f value -c name)"; done
cf1-0 eval(openstack project show ebf0f23f424c4417afd3e7bbf4e3900f -f value -c name)
The substitution from the second %s in printf works correctly, but I can't figure out how to execute the command.
The command needs to be executed in the same shell, and I cannot use environment variables.
Thanks.
** OUTPUT OF COMMANDS **
Here, -c var1 -c var2 can be placed in any order. -f just means print out the values, not the identifier.
[root@box~]# openstack server list --all -c Name -c ID -f value
2534ce5a-04da-4c7d-9ad5-b7bc466ae612 cf1-0
[root@box ~]# openstack server show 2534ce5a-04da-4c7d-9ad5-b7bc466ae612 -f value -c name -c project_id
cf1-0
ebf0f23f424c4417afd3e7bbf4e3900f
[root@box ~]# openstack project show ebf0f23f424c4417afd3e7bbf4e3900f -f value -c name
core
Desired output
===============
cf1-0 core
for var in $(...anything...), see BashPitfalls #1, and BashFAQ #1 describing the approach used in Inian's answer as a preferable alternative.PATH, you couldn't be using unqualified command names).