You are not logged in.
Hi all
SOLUTION ON 2 FIRST REPLIES
Why it not work?
#!/usr/bin/bash
PKG=gst-plugins-{bad,base,good,ugly}
# With {,double}quotes also not work
# PKG="gst-plugins-{bad,base,good,ugly}"
# PKG='gst-plugins-{bad,base,good,ugly}'
pacman -S $PKG
## Don't work!
# error: target not found: gst-plugins-{bad,base,good,ugly}
pacman -S gst-plugins-{bad,base,good,ugly}
#Works fine!
How can I pass an array/list/idonknownameofthat as argument to pacman(and other progams)?
[edit] ~> a better title
Last edited by souenzzo (2014-12-31 22:00:18)
Offline
Solution 1:
#!/usr/bin/bash
PKG=gst-plugins-{bad,base,good,ugly}
eval pacman -S $PKG
# Works fine too!
Last edited by souenzzo (2014-12-31 22:06:55)
Offline
Or let the expansion happen in the setting of the variable:
PKG="$(echo gst-plugins-{bad,base,good,ugly})"
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Or a mixed solution to allow any input on your script
#!/usr/bin/bash
PKG=gst-plugins-{bad,base,good,ugly}
PKG=$(eval echo $PKG) ## Edit: Don't use. See below ##
pacman -S $PKG
# Works fine too!
Thanks!
Last edited by souenzzo (2015-01-01 14:49:49)
Offline
`eval echo`? Is that really necessary?
┌─[Shiv ~ ]
└─╼ PKG=(gst-plugins-{bad,base,good,ugly})
┌─[Shiv ~ ]
└─╼ printf "%s\n" "${PKG[@]}"
gst-plugins-bad
gst-plugins-base
gst-plugins-good
gst-plugins-ugly
Offline
It's works too!
But that NEED the parenthesis. In my case, I want an "aways work"/"easy input". I think "eval echo" fits better.
Offline
It's works too!
But that NEED the parenthesis. In my case, I want an "aways work"/"easy input". I think "eval echo" fits better.
It "needs" the parentheses because it is initialising an array. And trust me, anything would be better than `eval echo`...
See http://mywiki.wooledge.org/BashFAQ/048
Offline