How to get exact command line string from shell?

后端 未结 2 489
北荒
北荒 2021-01-13 04:01

I know about $*, $@, \"$@\" and even ${1+\"@\"} and what they mean.

I need to get access to the EXACT

2条回答
  •  旧时难觅i
    2021-01-13 04:59

    In bash, you can get this from the shell history:

    set -o history
    shopt -s expand_aliases
    
    function myhack {
      line=$(history 1)
      line=${line#*[0-9]  }
      echo "You wrote: $line"
    }
    alias myhack='myhack #'
    

    Which works as you describe:

    $ myhack --args="stuff" * {1..10}    $PATH
    You wrote: myhack --args="stuff" * {1..10}    $PATH
    

    Also, here's a handy diagram:

提交回复
热议问题