Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

this is the content of the packageList file:

base-files
busybox
dnsmasq
dropbear
firewall
hotplug2
iptables
iptables-mod-conntrack-extra
iptables-mod-filter
iptables-mod-ipopt
iw
jshn
kernel
kmod-ath
kmod-ath9k
kmod-ath9k-common
kmod-cfg80211
kmod-crypto-aes
kmod-crypto-arc4
kmod-crypto-core
kmod-gpio-button-hotplug
kmod-ifb
kmod-ipt-conntrack
kmod-ipt-conntrack-extra
kmod-ipt-core
kmod-ipt-filter
kmod-ipt-ipopt
kmod-ipt-nat
kmod-ipt-nathelper
kmod-leds-gpio
kmod-ledtrig-default-on
kmod-ledtrig-netdev
kmod-ledtrig-timer
kmod-lib-crc-ccitt
kmod-lib-textsearch
kmod-mac80211
kmod-nls-base
kmod-ppp
kmod-pppoe
kmod-pppox
kmod-sched-connmark
kmod-sched-core
kmod-tun
kmod-wdt-ath79
libblobmsg-json
libc
libgcc
libip4tc
libip6tc
libiwinfo
libiwinfo-lua
libjson
liblua
liblzo
libnfnetlink
libnl-tiny
libopenssl
libubox
libubus
libubus-lua
libuci
libuci-lua
libxtables
lua
luci
luci-app-firewall
luci-app-qos
luci-app-tinyproxy
luci-app-upnp
luci-i18n-english
luci-lib-core
luci-lib-ipkg
luci-lib-nixio
luci-lib-sys
luci-lib-web
luci-mod-admin-core
luci-mod-admin-full
luci-proto-core
luci-proto-ppp
luci-proto-relay
luci-sgi-cgi
luci-theme-base
luci-theme-openwrt
miniupnpd
mtd
netifd
openvpn
opkg
ppp
ppp-mod-pppoe
qos-scripts
relayd
swconfig
tc
tinyproxy
uboot-envtools
ubus
ubusd
uci
uhttpd
wpad-mini
zlib

now I would like to pass it as argument to:

make image PROFILE=TLWR740 PACKAGES=packageList

this is BASH, how go do it? the content should be passed as argument in this way:

base-files busybox dnsmasq dropbear firewall hotplug2 iptables iptables-mod-conntrack-extra iptables-mod-filter iptables-mod-ipopt iw jshn kernel kmod-ath kmod-ath9k kmod-ath9k-common kmod-cfg80211 kmod-crypto-aes kmod-crypto-arc4 kmod-crypto-core kmod-gpio-button-hotplug kmod-ifb kmod-ipt-conntrack kmod-ipt-conntrack-extra kmod-ipt-core kmod-ipt-filter kmod-ipt-ipopt kmod-ipt-nat kmod-ipt-nathelper kmod-leds-gpio kmod-ledtrig-default-on kmod-ledtrig-netdev kmod-ledtrig-timer kmod-lib-crc-ccitt kmod-lib-textsearch kmod-mac80211 kmod-nls-base kmod-ppp kmod-pppoe kmod-pppox kmod-sched-connmark kmod-sched-core kmod-tun kmod-wdt-ath79 libblobmsg-json libc libgcc libip4tc libip6tc libiwinfo libiwinfo-lua libjson liblua liblzo libnfnetlink libnl-tiny libopenssl libubox libubus libubus-lua libuci libuci-lua libxtables lua luci luci-app-firewall luci-app-qos luci-app-tinyproxy luci-app-upnp luci-i18n-english luci-lib-core luci-lib-ipkg luci-lib-nixio luci-lib-sys luci-lib-web luci-mod-admin-core luci-mod-admin-full luci-proto-core luci-proto-ppp luci-proto-relay luci-sgi-cgi luci-theme-base luci-theme-openwrt miniupnpd mtd netifd openvpn opkg ppp ppp-mod-pppoe qos-scripts relayd swconfig tc tinyproxy uboot-envtools ubus ubusd uci uhttpd wpad-mini zlib

share|improve this question
2  
Try make image PROFILE=TLWR740 PACKAGES=$(cat packageList) –  MariusMatutiae Nov 16 '13 at 14:18
    
Or you can use that, too. –  Shiki Nov 16 '13 at 14:19
    
doesn't work unfortunatelly. I believe it's because it is passing the list as one name per line, not side-by-side. –  FernandoSBS Nov 16 '13 at 16:46
    
use quotes: PACKAGES="$(cat packageList)" so that the entire list is passed as a single parameter. –  Adrian Pronk Nov 16 '13 at 19:41
    
unfortunately, no. –  FernandoSBS Nov 16 '13 at 21:24
show 1 more comment

4 Answers

up vote 2 down vote accepted

You could do it that way:

  1. Declare variable $packages as array
  2. Read content of file packageList into $packages
  3. Run make with all array elements as list (${packages[*]})

Hence, this snippet should work:

declare -a packages
packages=($(< packageList))
make image PROFILE=TLWR740 PACKAGES="${packages[*]}"

A comment is appropriate about ${packageList[*]}. This expands to all array elements as one shell word. This is similar if you write "one two three" (note the quotes) on the command line.

A simple example, using a function first, which prints its first argument:

$ function first { echo $1 ; }
$ first one two three
one
$ first "one two three"
one two three

Now, with an array:

$ foo=(one two three)
$ first "${foo[@]}"
one
$ first "${foo[*]}"
one two three

So, with @ the shell splits the array into multiple shell words, using * it does not.

share|improve this answer
    
that also didn't work! how can that be possible? it produces no error, but it loads the default list. Probably ignoring the packageList. –  FernandoSBS Nov 16 '13 at 21:36
    
@FernandoSBS Are you sure, the make invocation is correct? Does it work, if you pass two or three packages manually, e.g. make ... PACKAGES="base-files busybox dnsmasq"? –  mpy Nov 16 '13 at 22:35
    
exactly, with manual pass it works. –  FernandoSBS Nov 16 '13 at 23:18
    
Please try ..."${packageList[*]}" instead. This will pass all packages as one shell word; ${packageList[@]} splits it into different shell words. (However this should be identical to Shiki's answer, then) –  mpy Nov 17 '13 at 10:33
    
Still don't work. More info: if I do: packageList="..." pasting manually the list of packages in the "..." it works. And when I cat $packageList it seems to be returning just cat: base-files: No such file or directory but when I cat packageList it returns all the list correctly –  FernandoSBS Nov 17 '13 at 11:29
show 4 more comments

Use tr to convert the newline characters to spaces:

make image PROFILE=TLWR740 "PACKAGES=$( tr '\n' ' ' < packageList)"

Seems tr only reads stdin so I've modified my command above to pass the file via stdin.

share|improve this answer
    
Also doesn't work. tr: extra operand packageList' Try tr --help' for more information. –  FernandoSBS Nov 16 '13 at 20:04
    
The command expansion should read: $(cat packageList | tr '\n' ' '). IMHO tr work's on stdin/out only. –  mpy Nov 16 '13 at 20:45
    
@FernandoSBS: Did you try tr --help ? What did it say? I've edited my answer. –  Adrian Pronk Nov 16 '13 at 23:19
    
@mpy: UUoC –  Adrian Pronk Nov 16 '13 at 23:20
    
what do you mean? what for tr --help ? –  FernandoSBS Nov 16 '13 at 23:54
add comment
List=`cat packageList`  
make image PROFILE=TLWR740 PACKAGES="$List"  

cat writes out the content of the file. (try it in cli.)

share|improve this answer
    
also doesn't work. I believe it's because it is passing the list as one name per line, not side-by-side. –  FernandoSBS Nov 16 '13 at 18:20
add comment
make image PROFILE=TLWR740 PACKAGES="`cat packageList | tr '\n' ' '`"

That should do it. cat prints the file contents, and the tr command replaces the newlines with spaces. (Note: this assumes that packageList is a file in the current directory, if it is elsewhere you will need to replace the name to include the correct path or use a variable to reference it)

share|improve this answer
    
This will split the package list over multiple command line arguments. You need to surround it with quotes. –  David Foerster Nov 17 '13 at 14:58
    
Right, thanks. Added quotes to my answer. –  SnoringFrog Nov 18 '13 at 6:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.