语法错误:换行符意外(预期为“)”)

#!/bin/sh

[ "$#" -ne 1 ]&& {  echo "$0**: accept one argument only" ; exit ;}
if [ -d "$1" ]; then

   while true
    do
     echo "PLEASE SELECT A CHOICE: "
     echo "1. List name of all files that end with .sh only in the given directory"
     echo "2. List name of all files that are writable in the given directory."
     echo "3. List name and size of the file with the largest size in the given directory."
     echo "4. List all filenames that have at least one digit in the given directory."
     echo "5. Exit"

     read -p "Enter x [ 1 - 5] " x
     case $x in
        1) find "$1" -maxdepth 1 -type f -printf "%f\n" -name "*.sh";;
        2) find "$1" -maxdepth 1 -type f -writable -printf "%f\n";;
        3) find "$1" -type f -exec ls -lh {} \; | sort -hr -k5 | head -n 1 | awk '{print $9 " " $5}' ;;
        4) find "$1" -maxdepth 1 -type f -printf "%f\n" | grep -i [0-9] ;;
        5)exit 0;;
   done
else
     echo "$1**: does not exist"; exit 
fi
评论
  • kquis
    kquis 回复

    You're missing an esac after the final 5) case and before the done to close out the case block.