Passing arguments by reference

后端 未结 9 1965
挽巷
挽巷 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:02

    This is what works for me on Ubuntu bash shell

    #!/bin/sh
    
    iteration=10
    
    increment_count()
    {
      local i
      i=$(($1+1))
      eval ${1}=\$i
    }
    
    
    increment_count iteration
    echo $iteration #prints 11
    increment_count iteration
    echo $iteration #prints 12
    

提交回复
热议问题