小编6eq*_*uj5的帖子

带参数的循环函数在另一个带参数的循环函数中

# Print $1 $2 times
function foo() {
    for (( i=0; i<$2; i++ )); do
        echo -n $1
    done
    echo
}

# Print $1 $2x$3 times
function bar() {
    for (( i=0; i<$3; i++ )); do
        foo $1 $2
    done
}

bar $1 $2 $3
Run Code Online (Sandbox Code Playgroud)

的理想输出foobar.sh @ 3 3

@@@
@@@
@@@
Run Code Online (Sandbox Code Playgroud)

但实际输出似乎只是

@@@
Run Code Online (Sandbox Code Playgroud)

将变量更改为bar()fromij产生所需的输出。但为什么?

scripting bash function arguments

1
推荐指数
1
解决办法
35
查看次数

标签 统计

arguments ×1

bash ×1

function ×1

scripting ×1