for-loop syntax


 
Thread Tools Search this Thread
# 1  
for-loop syntax

%%%%%

Last edited by lucasvs; 05-01-2012 at 06:25 AM..
# 2  
Are you sure this works ?
Code:
for A in db1.tab...


If its a file how does the system know it has to read the content? (my system cant ...(ksh) )
e.g. (AIX 6.1...)
Code:
n12:/home/vbe $ cat file1
OUTPUT
INPUT
OUTPUT
INPUT
n12:/home/vbe $ for i in file1; do echo $i; sleep 1;done           
file1
n12:/home/vbe $ for i in $(cat file1); do echo $i; sleep 1;done
OUTPUT
INPUT
OUTPUT
INPUT
# aix6.1

Q2 : there is no difference (except indentation...) between the 2 portions of code you submitted: A loop that starts when the previous finishes is a sequence... so one after the other...

Last edited by vbe; 12-16-2011 at 09:30 AM.. Reason: add code sample
# 3  
Have you read the answers to your previous post?
https://www.unix.com/unix-dummies-que...-end-file.html
# 4  
To vbe:
Thanks for the explanations !
So if I understand well, the indentation doesn't affect the sequence but it is just to read the script more easily.

To methyl:
Thanks !
I tried to run the utility but it didn't work.

---------- Post updated at 03:11 AM ---------- Previous update was at 03:00 AM ----------

To vbe:

By the way !
I don't know why, but my system can read the file when I write:

Code:
for A in file

but it is like the system didn't execute the second loop.

That's why I asked if it is right, when several file names differ only by the last number, to start the second loop by:
Code:
for C in ${B}_p*.temp

or
Code:
for C in *_p*.temp

 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Computers
Difficulty: Medium
"Windows NT" is a monolithic kernel.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use positional parameters in loop / while syntax in whiptail

I like to “optimize” / make more like a real program my bash script by replacing repetitious code which utilizes positional parameters. I am having two issues I cannot solve and would appreciate some assistance with resolving them. a) how to modify the whiptail checklist... (3 Replies)
Discussion started by: annacreek
3 Replies

2. Shell Programming and Scripting

What does xx mean in this while loop syntax?

I have a shell script which has this while loop line "while read tblName xx; do..." I understand how while loop works but don't know what does this xx stands for? (1 Reply)
Discussion started by: later_troy
1 Replies

3. UNIX for Dummies Questions & Answers

Syntax error in for loop

I am using simple for loop, but getting syntax error when I run the code code #!/bin/ksh pls enter number read n for(i=1; i<=n; i++) do echo $i done syntax error + pls enter number + read n (5 Replies)
Discussion started by: stew
5 Replies

4. UNIX for Dummies Questions & Answers

uanble to find while and for loop syntax in unix

Hi friends, I am unable to find for loop or while loop syntax on ksh shell,same syntax is working in other shell ,please suggest a way through. error :syntax error at line 2: `(' unexpected syntax used : for ((i=1;i<=$v1;i++)) thanks, Jcpratap (9 Replies)
Discussion started by: Jcpratap
9 Replies

5. Shell Programming and Scripting

IF loop syntax error

I am trying to run a menu option though IF loops. I keep getting errors not allowed the menu to be processed correctly. Currently it will accept the first 2 statements but then crash on the 3rd. The 2nd and 3rd have the same syntax, so I do not understand why it breaks. #!/bin/bash while... (4 Replies)
Discussion started by: Ironguru
4 Replies

6. Shell Programming and Scripting

for loop syntax

hi, I have to use for loop in my script. The below code is providing an output, 1,2,3,4,5..n. But i need to display the values one by one eg: it has to display the first value then exit from the loop and display the second value then exit till n(last value). for i in 1,2,3,4,5..n do ... (2 Replies)
Discussion started by: sreelu
2 Replies

7. Shell Programming and Scripting

While Loop Syntax help needed

Hi everyone, Can ny1 help me out regarding while loop arguments i.e. what does -gt -ge -lt -le means? actually i am new to while loops (2 Replies)
Discussion started by: jojo123
2 Replies

8. Shell Programming and Scripting

Problems with syntax in a loop (AWK)

Hi guys, I'm trying to loop through a number of files that is set by whatever is in a field. eg. The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited. I thought simple, count the number of fields in the field and then loop... (1 Reply)
Discussion started by: Peejay
1 Replies

9. Shell Programming and Scripting

syntax error in while loop

Hi, I have the following script (compile_mercury) and I get this error: I have no idea why...and I have written this script completely in linux (bash) and not in windows. **************** ./compile_mercury: line 136: syntax error near unexpected token `done' ./compile_mercury: line 136:... (1 Reply)
Discussion started by: habzone2007
1 Replies

10. Shell Programming and Scripting

for loop syntax trouble

i don't get what's wrong here. i'm writing a shell script that takes 1 argument (a number) from the command-line, but it's throwing an error: Syntax error: Bad for loop variable doesn't make much sense for (( i = 1; i = ${1}; i++ )) # error points to this line everytime do echo... (9 Replies)
Discussion started by: visitorQ
9 Replies

Featured Tech Videos