vendredi 7 septembre 2018

Shell: Nested IF Statements

I am having trouble getting a nested If statement to run.

This is the process I want to follow:

  • If param is set, check if param 2 is set.
  • If param 2 is set, say date set
  • If param 2 is NOT set, then ask for a date I need a date in the format YYYYMMDD
  • If param 1 and 2 are NOT set, run the get_files function.

Here is my code:

if [ -n "$1" ] then
    if [ -n "$2" ] then
        echo "date set"
    else 
        echo "I need a date in the format YYYYMMDD" 
    fi
else 
    get_files
fi

I get the error:

line 4: syntax error near unexpected token `else'

Any solutions?

Aucun commentaire:

Enregistrer un commentaire