Print bash arguments in reverse order

前端 未结 5 2174

I have to write a script, which will take all arguments and print them in reverse.

I\'ve made a solution, but find it very bad. Do you have a smarter idea?

5条回答
  •  终归单人心
    2021-01-07 05:55

    Could do this

    for (( i=$#;i>0;i-- ));do
            echo "${!i}"
    done
    

    This uses the below
    c style for loop
    Parameter indirect expansion (${!i}towards the bottom of the page)

    And $# which is the number of arguments to the script

提交回复
热议问题