Sponsored Content
Top Forums Shell Programming and Scripting [Solved] FOR loop / IF statement returning error Post 302848857 by jfxdavies on Friday 30th of August 2013 08:40:34 AM
Old 08-30-2013
[Solved] FOR loop / IF statement returning error

The code at the bottom is a simplified example of what we have.

If I use the following:
Code:
 [ $? != 0 ] && echo "echo failed"

$? returns 1

When I use
Code:
if [ $? != 0 ] ; then  echo "echo failed" ; fi

$? returns 0

Does anyone know what's wrong with this?

Using AIX 6.1 and KSH

Code:
for NUM in 1 2 3
do
    echo $NUM
    for LET in A B C
    do
        echo $LET
        [ $? != 0 ] && echo "echo failed"
        echo $?
    done
done

Thankyou.

Last edited by Scott; 08-30-2013 at 12:17 PM.. Reason: More code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For loop statement - catch error

I'm having a question about for loops. (bash) I have the following for example: for file in `ls *.txt` do read file ... done Now when there is a file present there is no problem, now when there is no file present I get the following output in my standard mail box : "No such... (4 Replies)
Discussion started by: lumdev
4 Replies

2. UNIX for Dummies Questions & Answers

Loop on array variable returning error: 0 not found

I'm guessing i have a syntax error. I'm not sure it get's past the the while condition. I get an error 0 not found. Simple loop not sure what I'm doing wrong. #!/usr/bin/ksh set -A MtPtArray /u03 /u06 tUbound=${#MtPtArray } echo $tUbound i=0 while ($i -lt $tUbound) do print... (4 Replies)
Discussion started by: KME
4 Replies

3. UNIX for Dummies Questions & Answers

For loop returning more values

Hi All, Thanks all of you for the help you provide to me. Well, I have one more problem, where I am trying to pull file system information in the loop and display the filesystem percentege. I am using following code to achive this, nut it's giving the weired output. My file system is ... (1 Reply)
Discussion started by: alok.behria
1 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Syntax error for awk in a loop

can some one please tell me what is the problem with my syntax:confused: I have 100 files in one folder 1. want to read each of the line by line 2. calculate their number of the words between the first word and the last word of each line 3. create file for each file with number of words... (8 Replies)
Discussion started by: A-V
8 Replies

5. Shell Programming and Scripting

for loop with internal unix command in statement throwing error

Hi I've gotten a plugin script that won't run. I keeps throwing an error at the following line. for BARCODE_LINE in `cat ${TSP_FILEPATH_BARCODE_TXT} | grep "^barcode"` do #something done The error reads ... (3 Replies)
Discussion started by: jdilts
3 Replies

6. Shell Programming and Scripting

[SOLVED] Problem in wait statement

Iam having a script which is used to load users and dumpfile in any given schema.Iam trying to autolog the script and have added two fucntion in it. function init_stdout_redirect { OUT_LOG=$1 OUT_PIPE=$(mktemp -u) # Create the output pipe mkfifo $OUT_PIPE # Save stdout and... (15 Replies)
Discussion started by: Vikram_Tanwar12
15 Replies

7. Shell Programming and Scripting

[Solved] 0403-057 Syntax error for if statement

I am getting the following error when I am running a script in ksh when trying to execute an if statement comparing two numerical values tstmb.sh: 1.5321e+08: 0403-057 Syntax error Below is my code snippet. #!/bin/ksh set -x TODAY=$(date +%y%m%d) for file in $(ls -rt *.log | tail... (11 Replies)
Discussion started by: kiran1112
11 Replies

8. Shell Programming and Scripting

[Solved] While loop error when add sqlplus command

Hi gurus, I hit a block when write the script. I need do while loop, in the loop I have code below. sqlplus -s abc/abc@abc <<EOF spool testwhile select * from dual; spool off exit; EOF when I run script with only this code, it works fine. if I add code as below: #!/bin/ksh ... (5 Replies)
Discussion started by: ken6503
5 Replies

9. Shell Programming and Scripting

[Solved] If statement in bash

I have the following code in bash, however "set red frmt" is not displayed. echo "iarg_rd = $iarg_rd" iarg_rd="2" if ; then echo "Hello World" fi if ; then frmt="${gap}${!frmt_titl_yl}" elif ; then frmt="${gap}${!frmt_titl_bk}" elif ; then echo... (2 Replies)
Discussion started by: kristinu
2 Replies

10. Shell Programming and Scripting

Statement returning error only launching the sh script via crontab

hi all, I created a sh script to import some tables from mysql to hive. No problem launching it manually, but if I schedule via crontab it returns me an error in the following part: #create an array containing all the tables for $dbname query="SELECT table_name FROM information_schema.tables'... (10 Replies)
Discussion started by: mfran2002
10 Replies
ROUND(3)								 1								  ROUND(3)

round - Rounds a float

SYNOPSIS
float round (float $val, [int $precision], [int $mode = PHP_ROUND_HALF_UP]) DESCRIPTION
Returns the rounded value of $val to specified $precision (number of digits after the decimal point). $precision can also be negative or zero (default). Note PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings. PARAMETERS
o $val - The value to round o $precision - The optional number of decimal digits to round to. o $mode - Use one of the following constants to specify the mode in which rounding occurs. +--------------------+---------------------------------------------------+ | Constant | | | | | | | Description | | | | +--------------------+---------------------------------------------------+ | | | | PHP_ROUND_HALF_UP | | | | | | | Round $val up to $precision decimal places away | | | from zero, when it is half way there. Making 1.5 | | | into 2 and -1.5 into -2. | | | | | | | |PHP_ROUND_HALF_DOWN | | | | | | | Round $val down to $precision decimal places | | | towards zero, when it is half way there. Making | | | 1.5 into 1 and -1.5 into -1. | | | | | | | |PHP_ROUND_HALF_EVEN | | | | | | | Round $val to $precision decimal places towards | | | the next even value. | | | | | | | |PHP_ROUND_HALF_ODD | | | | | | | Round $val to $precision decimal places towards | | | the next odd value. | | | | +--------------------+---------------------------------------------------+ RETURN VALUES
The rounded value EXAMPLES
Example #1 round(3) examples <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?> Example #2 $mode examples <?php echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9 echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10 echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9 echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9 echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9 ?> Example #3 $mode with precision examples <?php /* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5 /* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5 /* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5 /* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5 ?> CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The $mode parameter was introduced. | | | | | 5.2.7 | | | | | | | The inner workings of round(3) was changed to | | | conform to the C99 standard. | | | | +--------+---------------------------------------------------+ SEE ALSO
ceil(3), floor(3), number_format(3). PHP Documentation Group ROUND(3)
All times are GMT -4. The time now is 09:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy