dimanche 15 juillet 2018

Nested case statement within if then statement

I'm having trouble running a simple script, it works fine without the new case statement. What I would like is for my script to be able to "Catch" special characters that are "Accidentally" entered by a user as an argument on the command line and to output an error message. What I have so far is as follows:

if [ $# -eq 0 ]
then echo "Please enter a filename."
else
  if [ -f $1 ]
  then
    starting_data=$1
    sed '/^id/ d' $starting_data > raw1
    sed 's/-//' raw1 > raw2
    sed 's/-//' raw2 > raw3
    sed 's/,//' raw3 > raw4
    sed 's/,/:/' raw4 > raw5
    cut -f1 -d\  raw5 > col3
    cut -f2 -d\  raw5 > col2
    cut -f3 -d\  raw5 > col1
    paste -d\  col1 col2 col3 > final
    name="Joe"
    echo $name
    date
    cat final
  else
     if case $1 in
          [!@#$%^&*()-_=+{}\|;:'",<>?/]) echo "One or more characters not 
supported."
                                         echo "Please try again."
                                         ;;
        esac
     else
    echo "$1 cannot be found."
     fi
  fi
fi

Aucun commentaire:

Enregistrer un commentaire