For ksh, use the built-ins to save some processes and thus efficiency ('[' is an external program (test) and echo is also an external program, while '((' is built-in for math and print is built-in). While this example will not save much time, in a larger script or more complex script your savings will be significant:
(( )) is the best method - my opinion. You can use variable without $, about like in C.
Ofcourse you can use test command, but (( )) is nicer for numbers.
Yes, old bourne shell not included [, echo, true, false, ... but long time in many shells has been builtin echo, test, true, false, ... = posix shells.
So [, test, [[, ((, echo, print, printf, true, false, :, .. are builtin.
=> sometimes works little different, options are not always same, and so on. Some has done
just like posix has written, some has addon options.
In history we used
:
in forever loops, but today you can use true, it's not anymore external and so on.
Awk, sed, cut, tr, grep, expr, ... are still externals.
Ex. in ksh you can use command builtin to look ksh builtin. Also ksh93 include some builtin manuals. No need to read ksh manual.
I am trying to execute something like this
file=/tmp/test.txt
firstline=$(head -n 1 $file)
value=`echo $firstline | cut -d'=' -f2`
if
then
echo true
fi
i read the first line of a file, cut to the numeric value in the first line and check if it greater than 2
but for some... (11 Replies)
Hi
What is the difference between following commands
Command1
length=1
if ] ; then
echo "Hellow world"
fi
Command 2
length=1
if ] ; then
echo "Hellow world"
fi
which is correct usage from this (2 Replies)
I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Hi,
This is confusing me and I would appreciate some help.
Consider this script
#!/bin/ksh
typset -i stat=`ls -l $WORK/stat |wc -l`
if (( $stat < 20 ))
then
echo true
else
echo false
fi
If the value of $stat is say 29. When I run this above it echos true and not false.... (7 Replies)
Hi guys :D
I am still playing with my C handbook and yes, as you can see I have small problem as always :cool:
I wrote a C code
#include <stdio.h> #define MESSAGE 100 int main(void) { char input_mes - Pastebin.com
And when I try to compile it I get following errors from gcc
... (1 Reply)
I received a warning when I tried to compile my program that said:
warning: comparison between pointer and integer
Could you please explain to me what this means, and in what ways I could possibly fix this?
Thanks for your help! (2 Replies)
hi ,
i am trying to compre two strings
if ] or if ]
when the length of var1 is small (around 300-400 char ) it works fine
but when it is large (around 900-1000 chars) it fails
is there any limitations for this type of comparison ??? (1 Reply)
hi ,
i am trying to compre two strings
if ] or if ]
when the length of var1 is small (around 300-400 char ) it works fine
but when it is large (around 900-1000 chars) it fails
is there any limitations for this type of comparison ??? (3 Replies)
Guys,
I have two big numbers to multiply. In doing do I am getting integer overflow.
I managed to multiply number but this number is useless as KSh does not recognise it as
a valid number. Here is what I am doing
$ expr 999999999999 \* 100
276447132
I got the right value by doing... (2 Replies)