Explaination on if true


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Explaination on if true
# 1  
Old 02-24-2014
Explaination on if true

Hi Team,
I need to know why ppl use If true loop instead of just writing down the sequence of code lines.
1:
Code:
echo "Line1"
if true; then
echo "Line2"
fi
echo "Line3"

2:
Code:
echo "Line1"
echo "Line2"
echo "Line3"

Could you explain what does the if true loop make difference in 1st compare to 2nd code?

Regards,
Chandana
# 2  
Old 02-24-2014
Quote:
Originally Posted by chandana hs
Hi Team,
I need to know why ppl use If true loop instead of just writing down the sequence of code lines.
1:
Code:
echo "Line1"
if true; then
echo "Line2"
fi
echo "Line3"

2:
Code:
echo "Line1"
echo "Line2"
echo "Line3"

Could you explain what does the if true loop make difference in 1st compare to 2nd code?

Regards,
Chandana
I'm not sure what you mean by "if true loop". There is no loop here.

The only time I have seen code like this is during development where true is a placeholder for code to be added later. (But that should never be done without including a comment describing what code needs to be added.)

I have, however, e seen true used as the condition in a while loop to create an obvious infinite loop or a loop where the termination condition occurs in the middle of the loop instead of at the start of the loop or the end of the loop as in:
Code:
echo line1
while true
do      echo line2
        other stuff
        if [ something_failed ]
        then    break
        fi
        more stuff
done
echo line3

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-24-2014
It might have been used by the developer for debugging purposes. There might have been a condition there earlier for debugging and now its been replaced by true.
This User Gave Thanks to chacko193 For This Post:
# 4  
Old 02-24-2014
Hi,
Thank you.

I meant to say if true code block, not loop. Sorry.

But your answers explains me, that there is no special meaning to it. but used during development.

Regards,
Chandana
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Explaination on export command

Hello Team, Could you pls explain how export command works in below code: for i in ${!SDV_*}; do export $i done As per my understanding, if SDV_1=test1;SDV_2=test2;test1=var1;test2=var2then in for loop below export will get executed. export var1;export var2But, Will this... (3 Replies)
Discussion started by: chandana.hs
3 Replies

2. Shell Programming and Scripting

Explaination on Behavior of awk command

Hello Admin, Could you pls explain on the below behavior of the awk command. $ awk -F">20" "/Cyclomatic complexity/ && /;add;/{print \$1}" inspect_64d_369980 | awk '{print $NF}' | sort | tail -1 65 $var=`awk -F">20" "/Cyclomatic complexity/ && /;add;/{print \$1}" inspect_64d_369980 | awk... (3 Replies)
Discussion started by: chandana hs
3 Replies

3. Programming

Need explaination for a function please

can anybody explain a long fpathconf(int fildes, int name); what it do like 1- lim = fpathconf(STDIN_FILENO, _PC_NAME_MAX); printf("%s %ld\n", "_PC_NAME_MAX: ", lim); 2- lim = fpathconf(STDIN_FILENO, _PC_PATH_MAX); printf("%s %ld\n", " _PC_PATH_MAX ", lim); 3- lim =... (1 Reply)
Discussion started by: fwrlfo
1 Replies

4. Shell Programming and Scripting

Looking for awk code explaination

{ # print NF,NR,$0; if ( ($(NF-1) != 0) && ($NF != 0) ) {if ($(NF-1) > $NF) {percent=$(NF-1)/$NF-1;} else {percent=$NF/$(NF-1)-1;} } printf "%8.4f\%\n",percent*100; if (percent > 0.05||percent < -0.05 ){exit 1;} }' Use code tags please, ty. Also try to use a more... (1 Reply)
Discussion started by: bosmat shani
1 Replies

5. Shell Programming and Scripting

loop until true

Hi I need help with a script to loop unitl the statement is true done some thing like this until if then cp filename filename.anto fi done Regards, (3 Replies)
Discussion started by: antointoronto
3 Replies

6. UNIX for Dummies Questions & Answers

Funny but true....

Hallo everybody I am having a shell script called auto_run.sh in that only the first line works. the second line which has sed command is working only at the # prompt. not within the shell script. What could be the reason. *... sed 's/ //g' KTI >abc works in another shell script without the... (6 Replies)
Discussion started by: naushad
6 Replies

7. UNIX for Dummies Questions & Answers

is it true or not

I have heard for a long time that in maybe 2039 Unix will no longer be useable due the length of the date value. Anyone know anything about this? (4 Replies)
Discussion started by: dhlopomo
4 Replies

8. UNIX for Dummies Questions & Answers

True Shutdown help!

ok, i know the syntax that goes along with the Shutdown command... but my box never wants to ... well... shutdown.. it only halts, kills all the process's, stalls the comp to a complete stop, but does actually kill the monitor and/or shut off the physical computer. it will reboot properly though,... (3 Replies)
Discussion started by: 01000101
3 Replies

9. Linux

I would like to know the explaination.

Hi, I'm new to LINUX Scripting, I would like to know the full explaination of the below scripts. thank you. 1st script #! /bin/sh . /opt/home/hssadmin/cindy/formatxml.env `testrecord.scp` `testEXGU.scp` 2nd Script #! /bin/sh . /opt/home/hssadmin/cindy/formatxml.env cd... (1 Reply)
Discussion started by: AudreyEliza
1 Replies
Login or Register to Ask a Question