Passing arguments by reference

后端 未结 9 1954
挽巷
挽巷 2020-12-01 01:13

I want to ask if it is possible to pass arguments to a script function by reference:

i.e. to do something that would look like this in C++:



        
9条回答
  •  一整个雨季
    2020-12-01 02:10

    Eval should never be used on a string that a user can set because its dangerous. Something like "string; rm -rf ~" will be bad. So generally its best to find solutions where you don't have to worry about it.

    However, eval will be needed to set the passed variables, as the comment noted.

    $ y=four
    $ four=4
    $ echo ${!y}
    4
    $ foo() { x=$1; echo ${!x}; }
    $ foo four
    4
    

提交回复
热议问题