<分区>
我在 shell 脚本中有以下代码。一切正常。
#!/bin/bash
baseDirPath = '/stackoverflow/question'
newDir = '/stackoverflow/question/answers'
# first check some business condition
if [[ some condition here ]]
then
# check if base Directory path already exit
if [ -d $baseDirPath ];then
# check if new Directory exits or not, if not create one
if [ ! -d $newDir ];then
mkdir $newDir
if [ $? -ne 0 ] ; then
echo "error occurred while creating directory "
fi
fi
else
exit 1;
fi
fi
我觉得这是非常困惑且不是很干净的代码。 我对编程很陌生,所以不确定它如何干净。
我很好奇它是否可以变得更简单或者有其他方法可以做到这一点。
(上面没有展示完整的shell脚本,只展示了复杂的if-else部分。)