Variable to create a list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Variable to create a list
# 1  
Old 07-13-2011
Variable to create a list

Hi all,

I couldn't find an answer for this easy question, probably because the keywords I used in the search are too generic.

I just want to make a list of numbers using the value of a variable, like this:

Code:
NumFiles=$(ls | wc -l)
for i in {1..$NumFiles}; do
[...]

Say $NumFiles = 5. Bash reads that as the string "{1..5}", but it won't generate the sequence of numbers I want.
How can I do this?

Thanks
# 2  
Old 07-13-2011
Try:

Code:
for (( i = 1; i <= $NumFiles; i ++ )); do
...

# 3  
Old 07-13-2011
Code:
for i in $(seq 1 $NumFiles)

# 4  
Old 07-13-2011
Thanks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create variable from date

I have a requirement to send a trigger file (trigger_dayn.dat) to a remote server through the FTP trigger_dayn.dat - here the dayn is the day number. However the dayn is not sysdate. day 1 is from Monday 07:00.00 AM to Tuesday 06:59:59 AM and so on. So if the trigger file is generated say... (1 Reply)
Discussion started by: k_vikash
1 Replies

2. Shell Programming and Scripting

Reading content of a variable to create a new one?

Hello. I've written up a script, that populates a variable with a list of tapes returned from my library. For example: 701940L3,701941L3,701942L3,701943L3,701944L3,701945L3,701946L3,701947L3,701948L3 So now, the variable "TAPELIST" contains those numbers, delimited by commas. I'd like to... (6 Replies)
Discussion started by: Stephan
6 Replies

3. UNIX for Dummies Questions & Answers

Create a phone list

Is there a step by step instructions for creating a simple phone list? (3 Replies)
Discussion started by: organcory
3 Replies

4. Programming

how to create variable for all thread in c++

hello I have this code #include <sys/types.h> #include <unistd.h> #include <iostream> #include <pthread.h> #include<cstring> using namespace std; int var1=0; void doSomething() { var1 = 5; cout<<"Do S :"<<var1<<endl; sleep(1); var1 =7; (4 Replies)
Discussion started by: vip_a1
4 Replies

5. Shell Programming and Scripting

create variable name based on another variable's value

Hello, I am needing to create a variable and assign it a value based on the value of a previosly defined variable... I am using KSH.. Example: VAR1=COMPUTER1 I need another variable like ${VAR1}_FLAG="Y", so it would actually be COMPUTER1_FLAG="Y". I will be looping through many values in... (2 Replies)
Discussion started by: benefactr
2 Replies

6. UNIX for Dummies Questions & Answers

create a new environment variable??

Hi, I have say two programs File1: echo Enter A's Value read A export A File2: while do echo $A sleep 5 done (1 Reply)
Discussion started by: pbsrinivas
1 Replies

7. Shell Programming and Scripting

Create Variable for a PATH

Hello all, I need to create a variable that contains a path to a program. I'd like to reference that variable later in the script to execute the program. Does anyone have any ideas how I can accomplish this? Thanks, Mark :) (2 Replies)
Discussion started by: mmignot
2 Replies

8. Shell Programming and Scripting

How to create md5 Hash variable?

I have a script that runs the grub-md5-crypt command based on whether the pass_value variable is a non-zero string. The md5 hash is being created in the /opt/hostconfigs/$HOST file, but I can't echo $md5_value. It is blank. Is there a way to create and echo a md5 hash variable? if then... (1 Reply)
Discussion started by: cstovall
1 Replies

9. Shell Programming and Scripting

How to create a dynamic list?

Hi falks, I need to write a function in k-shell which cd to root directory and ask the user which sub directory you want to tar. The user will select directories untill quit. How to do it? Thanks in advance, Nir (4 Replies)
Discussion started by: nir_s
4 Replies

10. Shell Programming and Scripting

Trying to create variable, value not being held

I tried creating a variable with the awk command. The correct value is being printed to the screen; however, the variable max is not being set. The command "echo $max" is null. Any help would be greatly appreciated. Thank you. cat test.txt: -rw-r--r-- 1 root root 0 2005-01-12 20:51... (2 Replies)
Discussion started by: cstovall
2 Replies
Login or Register to Ask a Question