i need some help for a very siple script, i don't get were the fault is. The script :
#!/bin/bash
declare -i s
declare -i m
declare -i h
if [ "$3" < 50 ]; then s=$3+10 m=$2 h=$1
else if ["$2" < 50 ];
then s=$3-50 m=$2+1 h=$1
else s=$1-50 m=$2-50 h=$1+1 fi
fi
echo "$h:$m:$s"
The script add 10sc to the time we've entered.
I get this error message : "sub_change_dirrect: line 14: syntax error: unexpected end of file"
There are three obvious errors:
else s=$1-50 m=$2-50 h=$1+1 fi
, the wordfi
is not treated as a keyword, because it is not the first word in the command. To the shell, this looks like three assignments that apply to the commandfi
. If you ever got to execute this line, you'd see an errorbash: fi: command not found
. Putfi
on a line of its own (or put a;
before it).[ "$3" < 50 ]
is the same as[ "$3" ] < 50
— it's the command[ … ]
(which can also be writtentest
) with the sole argument"$3"
, and with an input redirection from the file50
. Either use the numeric comparison operator-lt
, or use an arithmetic instruction(( … ))
. The single bracket construct is an ordinary built-in command, so special characters such as<
retain their normal meaning. The double parenthesis construct is special syntax, and you can use<
as a numeric comparison operator inside.["$2" < 50 ]
is missing a space after the opening bracket.Also the usual convention in shell scripts is to put a newline after
then
andelse
. Furthermore, instead of anelse
block that consists entirely of anif
statement, you should useelif
. And please indent consistently.P.S. I haven't reviewed your logic. You seem to be looking for
date +%T -d 'now + 10 seconds'
.You forget to a
;
after the nestedfi
statement