Reputation: 1107
I am trying to populate a global variable of type array in a bash shell script. I was using subshell in a function and i understand now that after the code executes all is lost and the global declared var wasn't set with the new value. Now i am trying a different approach but still doesn't seem to work well. This is the code:
declare -a arr
let i=1
function availableDevices {
while read line #get list of devices
do
if [ -n "$line" ] && [ "`echo $line | awk '{print $2}'`" == "device" ]
then
device="`echo $line | awk '{print $1}'`"
echo "Add $device"
arr[i]="$device"
let i=$i+1
fi
done < <(adb devices)
echo "devices: ${arr[*]}"
}
When i call this function this error appears:
name.sh: cannot make pipe for process substitution: Function not implemented
I am new to scripting and probably is self explanatory but i don't get it. HOw can the function not be implemented? Thanks
Upvotes: 1
Views: 213
Reputation: 2541
make sure that there's actually bash, not sh, specified as hash-bang, as it seems that the message comes from using the "< <(" bashism. Also try: line="a b c"; set -- $line; echo 2 see whether that could have any use in your script, instead of echo $line | awk ..., alternatively, "Here strings" are often preferred over piping output of echo. A Here string looks like this (example): rev <<< test
Upvotes: 1