When replacing external commands in a shell script, I used an array to get rid of awk NF .
Now, since I moved from bash to POSIX sh, I cannot get the array marked on the right:
#!/bin/bash export RANGE="0 1 4 6 8 16 24 46 53" RANGE=($RANGE) echo arrayelements: $((${#RANGE[@]})) LAST=$((${#RANGE[@]}-1)) echo "Last element(replace NF): ${RANGE[$LAST]}"
I use OpenBSD, sh and is the same size as ksh. Moving above to /bin/sh , it seems that the following does not work:
set -A "$RANGE" set -- "$RANGE"
How could I implement the above script in /bin/sh ? (Note that it works fine if you call bash with --posix , this is not what I'm looking for.)
arrays bash posix sh
Charles
source share