Need tokens in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need tokens in shell script
# 1  
Old 10-01-2010
Question Need tokens in shell script

Hi All,

Im writing a shell script in which I want to get the folder names in one folder to be used in for loop.

I have used:
Code:
packsName=$(cd ~/packs/Acquisitions; ls -l| awk '{print $9}')
echo $packsName
o/p: opt temp user1 user2

ie. Im getting the output as a string.

But I want to use these names inside 'for .. in ' loop.
eg.
Code:
for var in opt temp user1 user2
do 
  statements;
done

Can anybody help me to get this tokenised?

Thanks.


Moderator's Comments:
Mod Comment Please use code tags, thank you

Last edited by Franklin52; 10-01-2010 at 07:11 AM..
# 2  
Old 10-01-2010
Have you tried this?
Code:
for var in $packsName
do
  ...
done

# 3  
Old 10-01-2010
or this:
Code:
cd ~/packs/Acquisitions
for var in *
do
  ...
done

# 4  
Old 10-01-2010
Thanks a lot!!

It worked both ways.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Reading tokens

I have a String class with a function that reads tokens using a delimiter. For example String sss = "6:8:12:16"; nfb = sss.nfields_b (':'); String tkb1 = sss.get_token_b (':'); String tkb2 = sss.get_token_b (':'); String tkb3 = sss.get_token_b (':'); String tkb4 =... (1 Reply)
Discussion started by: kristinu
1 Replies

2. Shell Programming and Scripting

Getting error -: more tokens expected in shell script

Hi can someone help me to resolve the error for this condition if ] && ]; then i am passing the values $k and $kkm i am getting the error like "-: more tokens expected" Thanks in Advance (5 Replies)
Discussion started by: makigate
5 Replies

3. Shell Programming and Scripting

+: more tokens expected

Hey everyone, i needed some help with this one. We move into a new file system (which should be the same as the previous one, other than the name directory has changed) and the script worked fine in the old file system and not the new. I'm trying to add the results from one with another but i'm... (4 Replies)
Discussion started by: senormarquez
4 Replies

4. Shell Programming and Scripting

Script - Expression not complete more tokens expected

I have the following script to output a report of response times - but it is throwing the error: ./jobname: -: 0403-053 Expression is not complete; more tokens expected. Here is the code, any ideas what the problem is? (line 46 is simply, LC=0) FILE2=/templogs/access_log... (9 Replies)
Discussion started by: daveaasmith
9 Replies

5. Shell Programming and Scripting

Replacing tokens

Hi all, I have a variable with value DateFileFormat=NAME.CODE.CON.01.#.S001.V1.D$.hent.txt I want this variable to get replaced with : var2 is a variable with string value DateFileFormat=NAME\\.CODE\\.CON\\.01\\.var2\\.S001\\.V1\\.D+\\.hent\\.txt\\.xml$ Please Help (3 Replies)
Discussion started by: abhinav192
3 Replies

6. Shell Programming and Scripting

Shell Script to replace tokens in multiple files

I have multiple script files that I have created, that allow me to simply replace a few tokens at the top of the file, and then not have to go through the actual script and change anything. I have about 10 of them, but I was hoping to find a way to write a small script that would allow me to input... (20 Replies)
Discussion started by: cbo0485
20 Replies

7. Shell Programming and Scripting

Shell script to parse/split input string and display the tokens

Hi, How do I parse/split lines (strings) read from a file and display the individual tokens in a shell script? Given that the length of individual lines is not constant and number of tokens in each line is also not constant. The input file could be as below: ... (3 Replies)
Discussion started by: yajaykumar
3 Replies

8. Shell Programming and Scripting

: + : more tokens expected

Hello- Trying to add two numbers in a ksh shell scripts and i get this error every time I execute stat1_ex.ksh: + : more tokens expected stat1=`cat .stat1a.tmp | cut -f2 -d" "` stat2=`cat .stat2a.tmp | cut -f2 -d" "` j=$(($stat1 + $stat2)) # < Here a the like the errors out echo $j... (3 Replies)
Discussion started by: Nomaad
3 Replies

9. Shell Programming and Scripting

reverse tokens with sed

I currently use this bash for loop below to reverse a set of tokens, example "abc def ghi" to "ghi def abc" but in looking at various sed one liner postings I notice two methods to reverse lines of text from a file (emulating tac) and reversing letters in a string (emulating rev) so I've spent some... (1 Reply)
Discussion started by: markc
1 Replies

10. UNIX for Dummies Questions & Answers

tokens in unix ?

im trying to remove all occurences of " OF xyz " in a file where xyz could be any word assuming xyz is the last word on the line but I won't always be. at the moment I have sed 's/OF.*//' but I want a nicer solution which could be in pseudo code sed 's/OF.* (next token)//' Is... (6 Replies)
Discussion started by: seaten
6 Replies
Login or Register to Ask a Question