Problems passing strings within an array

Print Friendly

By hungryd

i have a list of apps that i need to forcequit and, from time to time, that list changes. perfect excuse to manage a single array! however, my strings with spaces aren’t passing as i’d like them to. here’s the simple script:

Code:

#!/bin/sh

#-----Array
apps=( firefox-bin firefox JavaApplicationStub groupwise "Google Chrome" "Microsoft Word" )

for i in "${apps[@]}"
do
killall $i
done
exit 0


when i generate verbose feedback, i’m seeing each app in question quit EXCEPT for those with spaces. on a mac, in the command line, i have to type the following to forcequit word and chrome:

Code:

killall Microsoft Word
killall Google Chrome


but i can’t seem to find a way to paste the correct syntax into the array to get these applications to quit as the others do. in the above script example, the result just says:

“+ for i in ‘”${apps[@]}”‘
+ killall ‘Microsoft’ Word
No matching processes were found”

any thoughts on what i might be missing?

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

FavoriteLoadingAdd to favorites

Leave a Reply

Your email address will not be published. Required fields are marked *