Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash递归程序_Bash - Fatal编程技术网

Bash递归程序

Bash递归程序,bash,Bash,以下是我目前的功能: function create { a=$3 while [ $a -lt $secondnum ] do echo "mkdir $1/$a" if [ $2 -lt $firstnum ] then sum=$(($2+1))

以下是我目前的功能:

function create {
        a=$3 
        while [  $a -lt $secondnum ]
        do
                echo "mkdir $1/$a"
                if [ $2 -lt $firstnum ] 
                then
                        sum=$(($2+1))
                        d=$(($a))
                        create "$1/$d" $sum 0
                fi 
                a=$(($a+1))
        done    
}  
它的回声

mkdir hw1/0
mkdir hw1/0/0
mkdir hw1/0/0/0
mkdir hw1/0/0/1
mkdir hw1/0/0/2

它应该创建一个完整的目录,而不仅仅是一个分支。(例如hw//*分支)这是一个家庭作业项目,因此我需要使用bash。

我认为bash变量默认为全局变量。如果需要函数局部变量,则需要使用
local
关键字

$ help local
local: local [option] name[=value] ...
Define local variables.

Create a local variable called NAME, and give it VALUE.  OPTION can
be any option accepted by 'declare'.

Local variables can only be used within a function; they are visible
only to the function where they are defined and its children.

Exit Status:
Returns success unless an invalid option is supplied, an error occurs,
or the shell is not executing a function.

您期望的输出是什么?