How to access command line arguments of the caller inside a function?

后端 未结 8 928
囚心锁ツ
囚心锁ツ 2020-11-28 07:31

I\'m attempting to write a function in bash that will access the scripts command line arguments, but they are replaced with the positional arguments to the function. Is ther

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 08:14

    One can do it like this as well

    #!/bin/bash
    # script_name function_test.sh
    function argument(){
    for i in $@;do
        echo $i
    done;
    }
    argument $@
    

    Now call your script like

    ./function_test.sh argument1 argument2
    

提交回复
热议问题