Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm making an script that gives me a day like this jjj/yyyy when I give it a day like this dd/mm/yyyy and I need it to have an error when you don't write correctly but I'm starting and it's not working :(

#! /bin/bash

#Primero debes ingresar el mes
echo "Ingresa el número de un mes del año"
read mes

#Condicional 
#Dependiendo si coloca bien $mes
if [ "$mes" -lt 12 -a "$mes" -gt 0 ]; then
echo "muy bien, sigamos."
    else
    if [ "$mes" -gt 12 -a "$mes" -lt 0 ]; then
    echo "Creo que eso ya no es un mes!";
exit
fi

When I run it it says "syntax error near unexpected end of file"

Can anyone help me?

share|improve this question
    
Yes, someone can help you. –  Anthon Sep 12 '14 at 4:05

1 Answer 1

You missed a fi for inner if:

if [ "$mes" -lt 12 -a "$mes" -gt 0 ]; then
  echo "muy bien, sigamos."
else
  if [ "$mes" -gt 12 -a "$mes" -lt 0 ]; then
    echo "Creo que eso ya no es un mes!"
    # Missed fi here
  fi
  exit
fi
share|improve this answer
    
Thanks! That worked. –  Divshah Sep 12 '14 at 4:23
    
Now I have another issue, it doesn't display the second if part... I mean, If I put the number 13 it just ends, it doesn't say "Creo que esto ya no es un mes!" –  Divshah Sep 12 '14 at 4:24
    
@Divshah: 13 is not greater than 12 and less than 1 –  cuonglm Sep 12 '14 at 4:26
    
@Divshah, change your -a flag in the second if loop to -o. –  Ramesh Sep 12 '14 at 4:27
    
Finally I wrote this: –  Divshah Sep 12 '14 at 5:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.