Bash 迭代解中的递归解
我当时正在编写一个bash脚本,以使cd'ing到Dropbox文件夹(我在其中存储uni的课程作业)更容易。我决定使用参数,将我直接放入文件夹中,保存数周,或者父目录或包含所有参考资料的目录。我还决定使用递归验证输入(最初我通过将递归语句放在do while循环中创建了一个无限循环)。代码如下:Bash 迭代解中的递归解,bash,recursion,iteration,Bash,Recursion,Iteration,我当时正在编写一个bash脚本,以使cd'ing到Dropbox文件夹(我在其中存储uni的课程作业)更容易。我决定使用参数,将我直接放入文件夹中,保存数周,或者父目录或包含所有参考资料的目录。我还决定使用递归验证输入(最初我通过将递归语句放在do while循环中创建了一个无限循环)。代码如下: #!/bin.bash #changes to ~/Dropbox/UCP120/ function recurCall () { echo "Invalid input: $arg1 doe
#!/bin.bash
#changes to ~/Dropbox/UCP120/
function recurCall () {
echo "Invalid input: $arg1 does not exist."
echo "Enter a valid input"
read inputLoop
validateInput $inputLoop
}
function validateInput() {
arg1="$1"
reference="r"
##snip##
##if DIR is !null but non-existent loop and ask for input
elif [[ ! -d .../UCP120/"$arg1"/ || ! -d .../UCP120/Week\"$arg1"/ ]]; then
recurCall $arg1
##Recursive solutions don't require iterative control structures.
#while [[ snip (see if above) ]]; do
# recurCall $arg1
#done
fi
}
##Call the function. Get this ball rolling
validateInput $1
我的问题是: