Echo command, and then run it? (Like make)

前端 未结 6 1562
走了就别回头了
走了就别回头了 2021-02-02 12:49

Is there some way to get bash into a sort of verbose mode where, such that, when it\'s running a shell script, it echoes out the command it\'s going to run before running it? T

6条回答
  •  青春惊慌失措
    2021-02-02 13:33

    It's possible to use bash's printf in conjunction with the %q format specifier to escape the arguments so that spaces are preserved:

    function echo_and_run {
      echo "$" "$@"
      eval $(printf '%q ' "$@") < /dev/tty
    }
    

提交回复
热议问题