What is the purpose of the : (colon) GNU Bash builtin?

前端 未结 12 916
梦如初夏
梦如初夏 2020-11-22 14:01

What is the purpose of a command that does nothing, being little more than a comment leader, but is actually a shell builtin in and of itself?

It\'s slower than inse

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 14:21

    Another way, not yet mentioned here is the initialisation of parameters in infinite while-loops. Below is not the cleanest example, but it serves it's purpose.

    #!/usr/bin/env bash
    [ "$1" ] && foo=0 && bar="baz"
    while : "${foo=2}" "${bar:=qux}"; do
        echo "$foo"
        (( foo == 3 )) && echo "$bar" && break
        (( foo=foo+1 ))
    done
    

提交回复
热议问题