How to mark an array in POSIX sh?

前端 未结 3 1232
你的背包
你的背包 2020-12-10 03:20

While replacing external commands in a shell script, I used an array to get rid of awk\'s NF.

Now, since I moved from bash to POSIX sh, I cannot get the

3条回答
  •  轮回少年
    2020-12-10 04:01

    Arrays are not part of the POSIX sh specification.

    There are various other ways to find the last item. A couple of possibilities:

    #!/bin/sh
    export RANGE="0 1 4 6 8 16 24 46 53"
    for LAST_ITEM in $RANGE; do true; done
    echo "Last element(replace NF): $LAST_ITEM"
    

    or:

    #!/bin/sh
    export RANGE="0 1 4 6 8 16 24 46 53"
    LAST_ITEM="${RANGE##* }"
    echo "Last element(replace NF): $LAST_ITEM"
    

提交回复
热议问题