[Script] Conditions on parsing file

Hello,

I open a new POST, i consider that this is resolved

But i wish improve it.
In case 1, I would like to test the input file $1.
If $1 exist with no parameters but only comments, then send a message "Please..."
I tried somethings but no results.
Can you help me ?

#!/bin/bash
# set -vx

f1()    {
         echo $1 $2 $3 $4
        }


case $# in
        0)      echo -e "# comment1\n# comment2" > list_file
                read -p "Please fill in this list_file: "
                echo $REPLY
                ;;
        1)      [ -f "$1" ] || exit
                grep -v '^#' "$1" |
                        while read arg1 arg2 arg3 arg4
                                do f1 $arg1 $arg2 $arg3 $arg4
                                done
                ;;
        4)      echo -e "# comment1\n# comment2" > list_file
                echo $1 $2 $3 $4 >> list_file
                ;;
        5)      echo -e "# comment1\n# comment2" > $1
                f1 $2 $3 $4 $5 >> "$1"
                ;;

        *)      echo "error msg"; exit
esac

Have a nice day.

if [ -f "$1" ]
then
 ...
else
 ...
fi

Thanks :slight_smile:
It's OK

#!/bin/bash
# set -vx

f1()    {
         echo $1 $2 $3 $4                                       
        } 


case $# in
        0)      echo -e "# comment1\n# comment2" > list_file    
                read -p "Please fill in this list_file: "      
                echo $REPLY                                     
                ;;
        1)     if [ ! -f "$1" ] 
               then  > $1 && echo -e "# comment1\n# comment2" > $1
               read -p "Please fill in "$1": "
               echo $REPLY 
               else 
                   if [ -f "$1" -a $(grep -v '^#' "$1" | wc -l ) -ne 0 ]                             
                   then
                   grep -v '^#' "$1" |
                        while read arg1 arg2 arg3 arg4
                                do f1 $arg1 $arg2 $arg3 $arg4
                                done  
                   else 
                   read -p "Please fill in $1 : "
                   echo $REPLY
                   fi 
               fi
               ;;  
        4)      echo -e "# comment1\n# comment2" > list_file    
                echo $1 $2 $3 $4 >> list_file                   
                ;;
        5)      echo -e "# comment1\n# comment2" > $1           
                f1 $2 $3 $4 $5 >> "$1"                   
                ;;

        *)      echo "error msg"; exit
esac