Hi smart people! My question is almost unbelievably stupid: I cannot make conditional work!!:
if {3 > 2} { echo whatever }
if I write a script (called “****” for instance…) with this sentence, output is following:
./****: line 4: syntax error: unexpected end of file
Of course the script has a #!/bin/bash at the beginning… other much more complex “functionalities” work, but I can’t cope with “IF”. I looked up at “man if”, everything…
:)It is been a long time since I don’t use “IF”,I am still not a complete idiot…
THANKS!! the thing is I was trying to use “{ }” syntax instead of “] ; then”, etc. Should also work with “{”, I saw it thousands of times, but there is obvoiusly sth wrong with my “{”-sentence…
I will try “your syntax”, which has always been the traditinal one.
Thank you again!
It would help if we knew which language you were doing this in. I’ll
assume bash:
if 3 > 2 ] ; then
echo hi
fi
Good luck.
instaler wrote:
> Hi smart people! My question is almost unbelievably stupid: I cannot
> make conditional work!!:
>
> if {3 > 2} { echo whatever }
>
>
> if I write a script (called "" for instance…) with this sentence,
> output is following:
>
> ./: line 4: syntax error: unexpected end of file
>
> Of course the script has a #!/bin/bash at the beginning… other much
> more complex “functionalities” work, but I can’t cope with “IF”. I
> looked up at “man if”, everything…
>
> :)It is been a long time since I don’t use “IF”,I am still not a
> complete idiot…
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
instaler wrote:
> THANKS!! the thing is I was trying to use “{ }” syntax instead of “] ;
> then”, etc. Should also work with “{”, I saw it thousands of times, but
> there is obvoiusly sth wrong with my “{”-sentence…
>
> I will try “your syntax”, which has always been the traditinal one.
> Thank you again!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
Sorry, could not reply until now: yes I’m using typical #!/bin/bash, just because I’m used to . To use another shell the “/bash” path should be changed, right?
Why is it then that man pages for IF (man if) show the famous " if {…}{…} " syntax?
Right now I’m using openSuSE 11.0, with “its correspondent” kernel.
Again, it’s been a long time since I 've “lost contact with shells”, as with IF conditionals…
if(n)
Tcl Built-In Commands
if(n)
NAME
if - Execute scripts conditionally
SYNOPSIS
if expr1 ?then? body1 elseif expr2 ?then? body2 elseif … ?else?
This is the Tcl man page. ‘if’ is a bash builtin, so it doesn’t have its
own man page. man bash for details.
Good luck.
instaler wrote:
> Errata: “used to it”…
> Sorry, my first answer (for vij4yd) was written before I saw your first
> reply, I just didn’t see it…
>
> Thank you both!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
Yes, you could. Also you are right about the example… see the post
earlier I made with the same sort of thing but with an added semicolon and
‘then’.
Good luck.
instaler wrote:
> Thanks, killing ignorance again…So I could use this syntax with Tcl
> packages then.
>
> Just some feedback for the thread (vij4yd :)): this syntax
>
> if 3 > 2 ]
> echo whatever;
> else
> echo nothing;
> fi
>
> did not work, it needs a “then” after the first expression, connected
> by a semicolon.
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
instaler wrote:
> Sorry, could not reply until now: yes I’m using typical #!/bin/bash,
> just because I’m used to . To use another shell the “/bash” path should
> be changed, right?
> Why is it then that man pages for IF (man if) show the famous " if
> {…}{…} " syntax?
Bash if doesn’t have a man page, so you’ve been looking in the wrong place(s).
Bash does have ‘help’
$help help
help: help -s] [pattern …]
Display helpful information about builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise a list of the builtins is printed. The -s option
restricts the output for each builtin command matching PATTERN to
a short usage synopsis.
$help -s if
if: if COMMANDS; then COMMANDS; elif COMMANDS; then COMMANDS; ]… else COMMANDS; ] fi