DrMaemi / blog

1 stars 0 forks source link

[Bash] 함수 #160

Open DrMaemi opened 10 months ago

DrMaemi commented 10 months ago

shift-in-func.sh

#!/bin/bash

SCRIPT_ARGS=$@

my_func() {
    FUNC_ARGS=$@
    echo "FUNC_ARGS : $FUNC_ARGS"
    shift 2
    echo "shift 2 called"
    FUNC_ARGS=$@
    echo "FUNC_ARGS : $FUNC_ARGS"
    echo "my_func() return"
}

echo "SCRIPT_ARGS : $SCRIPT_ARGS"
my_func $SCRIPT_ARGS
SCRIPT_ARGS=$@
echo "SCRIPT_ARGS : $SCRIPT_ARGS"
shift 2
echo "shift 2 called"
SCRIPT_ARGS=$@
echo "SCRIPT_ARGS : $SCRIPT_ARGS"

실행

$ ./shift_in_func.sh 1 2 3 4 5
SCRIPT_ARGS : 1 2 3 4 5
FUNC_ARGS : 1 2 3 4 5
shift 2 called
FUNC_ARGS : 3 4 5
my_func() return
SCRIPT_ARGS : 1 2 3 4 5
shift 2 called
SCRIPT_ARGS : 3 4 5