declaring variable with for $(seq)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting declaring variable with for $(seq)
# 1  
Old 01-21-2009
declaring variable with for $(seq)

Hi guys. i have the following script:

Code:
1 #!/bin/bash
  2 linkcount=$(grep "/portal" tickets | wc -l)
  3 grep "/portal" tickets  > links
  4 for i in $(seq 1 $linkcount); do
  5 echo "BLYAT"
  6 let link$i=$(sed -n "$i"p links)
  7 echo $[link$i]
  8 done

the problem is, that "let" can`t define the variable, as variable looks like "/portal/ticket/show/090107-01666?status=open".
as you can see script should define a number of line(1-x) variables and echo them
Could you please suggest some options?
# 2  
Old 01-21-2009
Short and clear, use arrays. Have a read of this:

Arrays

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Declaring arrays in csh

Does anyone know how to declare an array in csh? I don't want to declare any elements in the array because I have a variable that represents the size of the array. For example: the array I want to declare is called sortList and it passes in the variable ARRAYSIZE that stores the value 8. (1 Reply)
Discussion started by: demet8
1 Replies

2. UNIX for Dummies Questions & Answers

PERL: Declaring Array

Is it possible to declare an array in the following way: @tmp = (@f,"String1","String2", "String3",@f); I'm getting the following error message: Array found where operator expected at Program.pl line 181, near "" (Missing semicolon on previous line?) ---------- Post updated at... (1 Reply)
Discussion started by: WongSifu
1 Replies

3. Shell Programming and Scripting

Declaring variables without initialization

I get an error in my shell script that line 1: )unexpected. Line 1 in my script (using sh by the way) is the variable I declared but did not initialize it. result= Is this wrong? How can I fix it? I am using the variable later in the program, so I figured I could just declare it first... (4 Replies)
Discussion started by: itech4814
4 Replies

4. Shell Programming and Scripting

Declaring variable with another variable

Hi All, The issue is that for changing name of the file i'm writing a script, there the at one point i need to declare a variable some thing like 'var1, var2, var3 ......' which has to store some value. Script as follows: for i in `echo xxxx_dddd_ccc_plsql_zz.sql |tr "_" ' '` do ... (2 Replies)
Discussion started by: girish_satyam
2 Replies

5. Shell Programming and Scripting

Using seq (Or alternative)

I usually just browse the forum/google for answers, however I've been stuck on a problem for a number of hours now and I've decided to join up and actually ask I've searched the forum ad naseum in an attempt to find answer to my query, however so far I have been unsuccessful. I'm no expert... (3 Replies)
Discussion started by: gtc
3 Replies

6. Programming

Declaring variables

Hey guys im facing a problem in declaring variables. i have a few classes like the one below... #ifndef _FINANCE_H #define _FINANCE_H #include <string> #include <iostream> #include <fstream> #include <stdlib.h> using namespace std ; class readStraitsTimesIndex { ... (3 Replies)
Discussion started by: gregarion
3 Replies

7. Shell Programming and Scripting

Using Seq As A Variable With Padded Digits

Hi all. Im trying to use a sequence in a while loop like this below. I need it for navigating a year, month, day folder structure where a user can input the start date and have it go to the desired end date. The script will grab a certain file on each day then move onto the next. Ive got all that... (3 Replies)
Discussion started by: Grizzly
3 Replies

8. Shell Programming and Scripting

Declaring functions in CSH

Hi all, It might seem like a very trivial question but I am new to shell scripting so excuse for that. I have an existing script in CSH. I need to create a function in the script which takes some parameters and returns a result. Can someone please let me know the syntax for function... (4 Replies)
Discussion started by: tipsy
4 Replies

9. Shell Programming and Scripting

Declaring Local Arrays

I have some function function() { fileNamelist=( `find Uploads -name "somePattern" | tr '\n' ' '` ) } but "local fileNamelist" makes it variable. How do I declare fileNameList as a local array in BASH? (1 Reply)
Discussion started by: ksh
1 Replies

10. UNIX for Dummies Questions & Answers

Declaring variable environments in .cshrc

Hi All, I have been trying to set variable environment for the JAVA_HOME but it doesn' work. The path set is as follows setenv JAVA_HOME "/usr/local/jdk1.3" setenv PATH $JAVA_HOME/bin setenv CLASSPATH ${JAVA_HOME}/lib/tools.jar:{JAVA_HOME}/lib/dt.jar can anyone suggest Me where am I and... (2 Replies)
Discussion started by: v_sharda
2 Replies
Login or Register to Ask a Question