if和case语句中的Bash编程循环

if和case语句中的Bash编程循环,bash,loops,if-statement,case,Bash,Loops,If Statement,Case,为什么当“title”变量输入null时,“if”语句上的代码会继续循环,但是对于case语句,我的脚本会有错误 echo -n "Title :" read title if [ -z "$title" ]; then echo "Please input a title" while [[ -z "$title" ]] ; do echo -n "Title: " read title done fi read autho

为什么当“title”变量输入null时,“if”语句上的代码会继续循环,但是对于case语句,我的脚本会有错误

 echo -n "Title :"
      read title   
   if [ -z "$title" ]; then
 echo "Please input a title"  
   while [[ -z "$title" ]] ; do
 echo -n "Title: "
      read title
   done
   fi



read author
     case "$author" in
     *[0-9,\""\!@#$%\(\)]*) echo "Please enter a name" ;;
      while  *[1-9,\""\!@#$%\(\)]*)"$author" ]] ; do
     echo -n "author "
          read author
      esac   
线路

 while  *[1-9,\""\!@#$%\(\)]*)"$author" ]] ; do
即使里面没有一大堆语法错误,也不允许出现。试试这个成语:

title=
while [ -z "$title ] 
do
    read -p "What is the title? " title
done
您有\“”,应该只有\“”。这是语法错误

另外,你不能把一段时间当作一个案例。试试这个,然后添加你想要的任何案例

while [ -z $author ]; do
echo "Please enter an author: "
read author  
case "$author" in
    *[0-9,\"\!@#$%\(\)]*) echo "First case - $author"
    ;;
esac
done