Print bash arguments in reverse order

前端 未结 5 2243

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:53

    bash:

    #!/bin/bash
    for i in "$@"; do
        echo "$i"
    done | tac
    

    call this script like:

    ./reverse 1 2 3 4
    

    it will print:

    4
    3
    2
    1
    

提交回复
热议问题