Seriuos problem with "IF"

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…:slight_smile:

try this

if  3 > 2 ]
    echo "yep. 3 is greater!!";
else 
    echo "this wont echo";
fi

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 SIGNED MESSAGE-----
Hash: SHA1

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…:slight_smile:
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJunjCAAoJEF+XTK08PnB5rHwP/j1UhWxPCeBNbFTlcj1HwVBH
UL8vwmc1bLfl4EOHHql80gjWo+mLOAI87oqYLqRHrJFCqGMMReBgtRTrTu7uhFr/
WH+C8s76Zh6Y7JYzjxOz9UMOGS1r7DHU29pf8qN0S/9U8FMf/gprgkYCN1uLytCs
qC5oFgu+UPZjoO/QsgM2+8/Ac94ZMc9p6wIWe3UqJNDgD2AkwhEqpn8GEjlw0iY4
SY2CiFwkA8CyqSsHvHPiwhqJFNDpDLZmMvGmSodtRPO6by/lDg0BuOsLUagotJ1b
A92jyAoX5Mbnowf4VKFkdqx/Cv5ax62vKugPFMDS7J7VizNvh000B3wNrNVm7Gw3
cIi9yWY59PeaxrpYbLiZqsW82QCDK654nAKTDErjrVKGBvi8g19Xnk+3wXar2+Dx
gIo6yGy0n+gsNRA5kIYNtbOD/B4C/sT6eRmAyXORbkgpKMIIT8ZgjJs9sJaN1x3b
M/KCkJY2ZHEyqsUjS0TIcxZWgGmcPcg/CzAXn6yzs9aKdOg9e/4Q7CpkfDVet9Z+
JIVxDY3gnOGVDCorD46pOvx7sc3AhM2N3c09117Z4BWD7mu2rOj6rWZs7fW+36qP
Agmws78grmikXeL7h59HkDPyFT86zXxQdE6BABBCkpiTLATF+qUXHcOL6lmB9K3b
OGkxEYOQMXJv7s0R/40+
=5BIz
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It may work in another shell, but not in bash.

Good luck.

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

iQIcBAEBAgAGBQJJunyVAAoJEF+XTK08PnB5jIkQALogAJDXPMkkpt+y8uNaqWJ9
ldm0lkXGFRS8tmo6C12QigQaecfE0YNKkGdPZ9TdbcIl3F+aHKN4daAb4f3Y7yRA
GO8SLtpkFnTXuVgpD4KQB5bjfeUeJYosu1pcJ75KD9MN5gHKzhj7EHCM64mqKk1n
P4/y7MvE+q6kk/NdkOSYKX3U808QZviT6M+jifBz5G6Kz4VGRwOW1mu3A6V9pp51
mx1nQkm4ojYXxxKDdgmRpRBaA0t9OO2udjKRi3ABY98L7iqVJQje9UsJkDTB0y6C
uGrfwLip3qr5mHuuETS0jlPihH6mThJ1fBeObvKMzML0eVN+vl3jFpYWRbjIZReA
mWrQFH7/y80ZJMF96938T5vVR6Fj89EkgZcFUzu4dwRvdTjCn+rjwDv+FbRi4tQW
RISaAVYE/5eJ7i55cHB4rUqEJdlST0gbqnc5SLe5uIpqpCOPPtnZ3XEqRdxM4+MI
WnyjGasP2AUQAjWAvXiRihfiq7MoQqH0YYicclOhvgB8M5Wb9zsWnA+7nXgU2EEB
2UkdWqtMzzKMGoHwzNBOBjEHZHzzVG+Nfd2WI7GY8jXKPnEuGW28Sz43lb0hCV4O
gUo/KBNz4u8Q6B0Q+dWoQKaw5DG4FiGyNN1YOD55Ub0oRgu3DmbMgh8IQTNhIf8o
D1P5elsXn9OKVOlgwpcQ
=yVxW
-----END PGP SIGNATURE-----

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…

Thank you for the info!

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 SIGNED MESSAGE-----
Hash: SHA1

man if

Look at the very top of the screen:

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

iQIcBAEBAgAGBQJJu7O2AAoJEF+XTK08PnB5s8YQAJAN2cyL4AEt6CblT33cpr5f
wb0tcjj2SV+ttzNPGvSsEG699WiVnEm3d5slOduGh0S9aX7rxFKn2cvMrF2bxKPT
t9oxGeCzAeeXuWQbyMWD4HYnYKjfk0hXzaf6cp16JRxaQHIlMzJFr9mr+tQICaDg
SS+yWtBwXp9w4BNwdb71+1ptWCmNZhT+SwX2JAf+SO9/eh2Dr1Y3J7sxEfpOGvEi
PZq3uF+WzqgbdYK8kXomQRJkPSNFLaOKAeFTsOI3Mqc3tt90QkczqDExEh/KSGA6
lyxRcjNrPYK/0odicZZxQRPnIvsGsM+YllGu0nudHjz+AWRZaMP7RrR6tRLYi6EA
gsmzq2RU8JBMf9IJNu2tYepEkTaMmH8iifkYoMFDqDFsbsiP/qT1t1WOxSvE8mjH
jbPUWLdpKMeij3kSe9ffa9dYVE+z4zavm3ES5pnqxw+xz3bz8EdSHh4E3HbE8bPH
+fhVUVfTO5QpJeiabW/VgqfitDXZngw0yGjSgG1xDMKkaaGxnjWtDPVRZljjvaHe
M22Jvmhp8GRuOJvjsaYV7mwdFpfphn5Ddi6qZROiYO8Fe674AjSM73t06vkmWrDg
7rJLR+E/7epDe0S5nMbiQE31AT6IOqJRgE8z8mqDY9GbgBSa749DKhH8aVam8nxw
VWSAs2M9zO2NyOqiHeUm
=tzz1
-----END PGP SIGNATURE-----

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 SIGNED MESSAGE-----
Hash: SHA1

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

iQIcBAEBAgAGBQJJu8B1AAoJEF+XTK08PnB5PVAP/1KgsN0wT8SwO4NG7526amAr
hHTZYA5K43UmU9e/LvYqivy/Z8mcCMGe3cCCBJiMvLfV9GtrVardXVNi4rYlDv+V
tFxsGGh710Sq9WeyeMojhvZ0HZ/TkhBgrA+DEm3Q5RLn0cYr/b4Kg6jH/1H3wKds
YFZSAIDLczi5pomJ8AnRPe3GUy9Tf1kqiJUbtHWmWYQC1rTsot/TuSrk34A3ogZ1
jiNQgytjXCamlfgGTXgsvwDEfLk98vemFagrt+zBhCJ6h6C5BidErHQmJXKCRokf
gKPaODvNsWpyp6Pptx6xZarhWJQtBeog2UizWz7ehVQinQypCzDK4SGIUZgVVhDe
902AGwqRv/GJicPZkduWMKXcl75nj4OZL0BeaL4YttwYZFd+k2Tw+aATFSISaCGp
I8VjhPXp3cTvnH5lv4uE5kOgxavrZEtKEPjlf/RS+rNNH5QWqJSdlT7W3p1Acvoe
YKVqmhKbq0upnDLH4F72btyRLnZAwxLxuzXZle+XPzdT8icdvzB3bVDJLUdzeZCK
MGV/KZjg98yMWbmYZFXW9wt/jwcZMI4eR/d9L+79yL6riaHJMhVpOHxTOFi4+LmZ
+j0a9iHlVn1QxCLCFC2qqECebgrEl0qg2vnq0evi/8OKfo+ktxK9w7woHil2pGBo
qnkmNbO5fUgPAYsqdUA2
=kp5C
-----END PGP SIGNATURE-----

Yes, thanks!, I used the example you wrote earlier, that one worked.

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

sorry about that.
my mistake :shame:
should’ve checked before posting :slight_smile:

Don’t worry!!Everything, everyinfo was of some help, besides it was a really quick answer!:slight_smile:

LittleRedrooster:thanks, ab@novell wrote that too.