[Solved] Need help understanding ksh scripting.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Need help understanding ksh scripting.
# 8  
Old 02-12-2014
Quote:
Originally Posted by Perderabo
… … …

Leaving off the $ is much faster and, provided that the variable only contains a simple scalar will give the same result.
Both ((expression)) and $((expression)) perform an arithmetic evaluation of expression. After evaluating expression, $((expression)) returns a string representing the resulting value. ((expression)) returns a 0 exit status if expression evaluates to a non-zero value and 1 otherwise.

Other than the time taken to format the results, there shouldn't be any noticeable difference in speed between ((expression)) and $((expression)).

Note that the standards require conforming shells to support arithmetic expansion ($((expression))). The standards explicitly allow for the arithmetic evaluation command (((expression))) to be provided, but do not currently require conforming shells to provide it. The standards also explicitly require applications that invoke nested subshells to separate the opening parentheses opening the subshell environments with one or more IFS characters to avoid an ambiguity in the grammar in shells that support the arithmetic evaluation command.
# 9  
Old 02-12-2014
I mean ((x+=1)) is much faster than (($x+=1))

And that is dependent on the code being in a loop. ksh precompiles loops and executes the compiled code. With the second form, ksh must expand the variable and then rescan the full resulting expression. With the first form ksh can use the compiled code with no rescan.
# 10  
Old 02-13-2014
Hi Robin,
I have changed the syntax as you menitoned and i tried.
Now it is working fine.
if [ $i -gt 1 ];

Thank you so much for your help... Smilie

Thanks
Shiva
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble understanding shell scripting (mostly wsname)

Am still learning Scripting and I come across a build command that I don't really understand if /local/bin/wsname 2>/dev/null; then base="`/local/bin/wsname`" export base fi if ; then /local/bin/wsname exit 1 fi WSNAME="$base"/ can some one in light me to what... (1 Reply)
Discussion started by: Wpgn
1 Replies

2. Shell Programming and Scripting

[Solved] Help understanding this code!!

Hi guys, I am still learning awk and much apprecated to shed some light on the following: the questions asked is below! { total = i = 0 do { ++i total += $i } while ( total <= 100 ) print i, ":", total } File used: cat test.do 45 25 60 20 10 105 50 40 33 5 9 67 108 3 5 4 (2 Replies)
Discussion started by: Apollo
2 Replies

3. Shell Programming and Scripting

[Solved] Shell scripting

I am new to write scripts. I want help to write a shell script to create 10 users and passwords to users. Can any please help me. (9 Replies)
Discussion started by: DONFOX
9 Replies

4. Shell Programming and Scripting

[Solved] KSH: Array/If Help

RedHat 5 KSH I am creating an array, and then using case to go through and count for specific words. Then the count gets stored as an expression. string='ftp rcp rsh telnet ftp ftp' set -A myarray $string FTPCOUNT="0" for command in ${myarray} do case $command in ftp) FTPCOUNT=`expr... (2 Replies)
Discussion started by: nitrobass24
2 Replies

5. Shell Programming and Scripting

[Solved] Help with Sort command (ksh)

hello everyone, I have file with de-limited values in random order shown below, where C1V0 represents column1 value1, C2V0 represents column2 value 2, and so on. Column0 is a constant value which i didn't represent in the sample input format. Column1 is a numeric column. Column2 is a... (0 Replies)
Discussion started by: angie1234
0 Replies

6. Shell Programming and Scripting

[Solved] AIX ksh script -d <- what does it mean?

I'm looking at a line in a script: && DRROOT="/dir1" || DRROOT="/dir2" I'm trying to understand it. Is there a "-d" command and is it seeing if /dir1 exists and, if so, set an environment variable named DRROOT to "/dir1", else set DRROOT to "/dir2" ? Thanks, -dog ---------- Post... (0 Replies)
Discussion started by: landog
0 Replies

7. Shell Programming and Scripting

Understanding Shell Scripting

Hi Gurus, Im new to Shell scripting. I have a shell script which basically sends an email when called thorugh my ETL tool. Wanted to understand the its functionality in detail. Would be great it any one can explain what exactly the commands to #!/bin/sh # Dummy UUCP rmail command for... (1 Reply)
Discussion started by: r_t_1601
1 Replies

8. Shell Programming and Scripting

[Solved] need help in shell scripting

Hi Friends, Please help me with the following problem: I have a text file with the following lines: Dated: 8/11/2011 <br> Time : 0000 <br> ============== <br> --------------------------------------<br>Data Upload Time =4:51:52... (2 Replies)
Discussion started by: anuajay1988
2 Replies

9. Shell Programming and Scripting

Understanding of a script as a scripting newbie

Hi! I have the following script and do not understand part of it. I have a very little understanding of scripting. The script is for Nagios to check the response of fast-com.de. The guy who has written it is no longer in the company. #!/bin/sh PATH=/adm/bin:/bin:/usr/bin export PATH ... (2 Replies)
Discussion started by: locutus01
2 Replies
Login or Register to Ask a Question