answersLogoWhite

0

For loop syntax in unix

Updated: 10/3/2023
User Avatar

Wiki User

15y ago

Best Answer

For loop can be used in following Ways:- Syntax: for var in list do commands done where list is basically the list of the values u want to traverse on, consider an example: suppose u want to display ur name 10 times we ca use for loop as: for var in 1 2 3 4 5 6 7 8 9 10 do echo "$name" done OR for var in {1 .. 10} do echo "$name" done OR the best way(analogous to c) for (( i = 0; i <= 10; i++) do echo "$name" done

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

for file in `ls $HOME/$1/` do echo "Print the directory : \c" done for file in `ls $HOME/$1/` do echo "Print the directory : \c" done

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: For loop syntax in unix
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the definition and syntax of for next loops?

loop within in a loop is called for next loop


Syntax of for loop in c language?

for(i=0;i&lt;=0;i++)


How do you create dummy file in unix?

using touch command of UNIX. syntax touch &lt;filename&gt; will create dummy regular file.


Is it possible to use a for loop in place of a while loop?

Yes. while loop consist of only condition statement to make for loop look as while loop we can use syntax shown below: for(;condition;) eg: for(;i&lt;=n;)


Explain the use of chmod command in Unix with syntax?

To complex to answer completely here - see related link.


What is difference between select Case statement and nested loop in c programming in UNIX?

UNIX has no bearing on the C language; it is cross-platform. There is no select/case in C, you probably meant switch/case. However, a switch/case is a conditional jump while a nested loop is a loop within a loop. Besides the C language they have nothing in common with each other.


What is the difference between do while and for loop?

do { //statements }while(condition); The statements inside the block get executed at-least once, no matter what condition you have placed. Only from the 2nd time the condition is checked, simply because the condition is at the last. for(initialization; condition; updation) { //statements } Here the statements don't get executed even once if the condition fails initially. The condition is at the entry itself.


Is an infinite loop an example of a syntax error?

No. A syntax error is a statement that fails to compile. Infinite loops are simply loops for which the number of iterations is unknown. However, all loops, whether counted loops or infinite loops, must have a reachable exit condition. If a loop does not have a reachable exit condition then it is a logic error, not a syntax error.


How do you use if statement syntax in a for loop?

You can use any number of if staments within a for-loop, eg: for (i=0; i&lt;10; ++i) { if (i=1) printf ("%d=1\n",i); }


What are while loop in vb.net?

The while loop in vb.net uses the syntax form which provides a way to continue iterating while one or more conditions are true.


What is the significance of write and talk command in UNIX?

About write Send a message to another user. Syntax write person [ttyname] About talk Talk with other logged in users. Syntax talk person [ttyname]


What would you recommend for a laptop Solaris or Unix?

Your question is an unanswerable loop. Solaris is a Unix system. One cannot be better or worse than the other because one is a subdivision of the other.