Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Need to get a loop variable from output of a command Post 302721529 by pat_pramod on Thursday 25th of October 2012 01:37:08 PM
Old 10-25-2012
Need to get a loop variable from output of a command

Hi,

I am trying to get a loop counter i and set its value as the ouput of a command:

Code:
i=`printmo TEST1 | grep -i TEST2 | wc -l`

Then I want to use i as counter to run a loop i number of times.
Like if i gets a value of 5 I'll have to run loop 5 times.
But will i here be a numeric variable? If it won't be numeric then how can I make it a numeric variable and use it as couter to run the loop.

Please help. I tried to search but didn't get what I am looking for.

Thanks in advance,
Pramod

Last edited by Scott; 10-25-2012 at 02:59 PM.. Reason: Code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command output to a variable.

With cut -c 8-13 myfile, I am getting some numeric value. In my shell script I am trying to assign something like this, var=cut -c 8-13 myfile But at the time of execution I am getting -c is not found. If I dont assign, then script executes well. Can we not simply use the value from one... (8 Replies)
Discussion started by: videsh77
8 Replies

2. Shell Programming and Scripting

While loop using command output...

If I run this command networksetup -listallnetworkservices I get the following output. Ethernet AirPort *Parallels Host-Guest *Parallels NAT MY VPN Ethernet 2 I want to make changes to only anything that contains the word "Ethernet" which I can do with grep. But What I really need a... (6 Replies)
Discussion started by: elbombillo
6 Replies

3. Programming

Command output into a variable

Hi, with this command: cu -l /dev/ttyACM0 -s 9600 > name.txt I put the output of the port in a txt Is posible to do the same (or similar) in a var directly, inside a C program? cu -l /dev/ttyACM0 -s 9600 > variable ? I have trying this withs pipes, but i dont know how to... (6 Replies)
Discussion started by: daaran
6 Replies

4. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

5. Shell Programming and Scripting

Redirect output of command line to for loop

I would like to redirect output of command line in for loop as $line. Output should be processed as line but instead it throw whole output. Could somebody help me on how to redirect output of command line and process it line by line without sending output to any file. below is my code ... (1 Reply)
Discussion started by: tapia
1 Replies

6. Shell Programming and Scripting

Output of find command to variable?

Hi, I'd like to assign the output of the find command to a variable. What I need is to run the find command, and if it returns zero files, the program exits. so i'm trying to assign the output of the find command to the $var1 variable....and then if this is less than one, I echo a... (2 Replies)
Discussion started by: horhif
2 Replies

7. Shell Programming and Scripting

Print for loop variable in output too

Hi, This is my input file cat input chr1:100-200 chr1:220-300 chr1:300-400 Now, I would like to run a program that will take each of the input record for i in `cat input`; do program $i | wc -l;done the output will be something like 10 20 30 But, I would like to print the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

8. Shell Programming and Scripting

Use while loop - output variable

I'm very much a newbie and hence why this is going to be a stupid question. I'm attempting to create a korn shell script that pulls zone file locations and includes the copy command in the output. What? getzonedir.ksh #!/bin/ksh while read -r domain do ls */*"$domain" > $dir1 echo "cp... (5 Replies)
Discussion started by: djzah
5 Replies

9. UNIX for Beginners Questions & Answers

How do I assign the output of a command to a variable within a loop in bash?

In the else of the main if condition . else set lnk = $(readlink -f <path> | cut -d '/' -f7) echo "$lnk" if ] When I run the above on command line , the execution seems to be fine and I get the desired output. But when I try to assign it to a variable within a loop... (12 Replies)
Discussion started by: sankasu
12 Replies
while(n)						       Tcl Built-In Commands							  while(n)

__________________________________________________________________________________________________________________________________________________

NAME
while - Execute script repeatedly as long as a condition is met SYNOPSIS
while test body _________________________________________________________________ DESCRIPTION
The while command evaluates test as an expression (in the same way that expr evaluates its argument). The value of the expression must a proper boolean value; if it is a true value then body is executed by passing it to the Tcl interpreter. Once body has been executed then test is evaluated again, and the process repeats until eventually test evaluates to a false boolean value. Continue commands may be exe- cuted inside body to terminate the current iteration of the loop, and break commands may be executed inside body to cause immediate termi- nation of the while command. The while command always returns an empty string. Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the while command starts execut- ing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iter- ation), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10: set x 0 while {$x<10} { puts "x is $x" incr x } SEE ALSO
break(n), continue(n), for(n), foreach(n) KEYWORDS
boolean value, loop, test, while Tcl while(n)
All times are GMT -4. The time now is 06:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy