Hi,
Can you please help me with this one: I write an "if" statement, something like this:
if[size -ge 700]
then
echo "big file"
else
echo "normal file"
and I get an error: `'then is not expected
Thanks in advance
Hi,
Can you please help me with this one: I write an "if" statement, something like this:
if[size -ge 700]
then
echo "big file"
else
echo "normal file"
and I get an error: `'then is not expected
Thanks in advance
syntax is wrong..
if [ $size -ge "700" ] ; then
.
.
I think you need to drop the quote marks around the 700 or else it is a string rather than an integer?
it won't make any difference
home> size=700
home> if [ $size -eq "700" ] ; then
> echo Y
> fi
Y
home> if [ $size -eq 700 ] ; then
> echo Y
> fi
Y
Just a short note besides what has been mentioned in the other posts:
tyler_durden
In UNIX shell, white space (one or more space/tab) is important to serve as separator. In the "if" command, the syntax is:
"if" <space> <expression>
then
<command>
<command>
"fi"
The <expression> in your case is:
"[" <space> "$size" <space> "-ge" <space> "700" <space> "]"
Since you are comparing numeric value, you need to use:
-lt, less than
-le, less than or equal to
-gt, greater than
-ge, greater than or equal to
-ne, not equal to
If you are comparing string,
=, equal
!=, not equal to
Since semi-colon ( enables mutli commands in a single line,
if [ $size -ge 700 ]; then
is in fact equivalent to
if [ $size -ge 700 ]
then
thanks, guys...now it is working!!