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

后端 未结 8 863
囚心锁ツ
囚心锁ツ 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:10

    # Save the script arguments
    SCRIPT_NAME=$0
    ARG_1=$1
    ARGS_ALL=$*
    
    function stuff {
      # use script args via the variables you saved
      # or the function args via $
      echo $0 $*
    } 
    
    
    # Call the function with arguments
    stuff 1 2 3 4
    

提交回复
热议问题