End of loop condition required???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting End of loop condition required???
# 1  
Old 07-16-2007
End of loop condition required???

Hi

i have a variable with lots of tokens seperated with spaces.

e.g VAR="ABC DEF GHSD GHQS TUTSD JHDTQ QDHQ CDQKDGQ WQUTQD DQUTQD DQJGDQ QDTQD WDQUTQDU QDUGQD QDJGQD DQUTDUQ QDUIDTQ"
i want to separate all of the above tokens and call a script with each of the token e.g sh script.sh <TOKEN>



Can anybody provide the logic script ? I am cofused about the end of the loop condition.

Thanks
# 2  
Old 07-16-2007
Can you show us what you have ? Perhaps, we can guide you better when we see the script.
# 3  
Old 07-16-2007
#!/user/bin
NAMES=`ls *.txt`
echo $NAMES

The content of this NAMES variable are TOKENS seperated by spaces.

i want to pass each token to another script called run.sh as follows:


while [<ALL tokens in $NAMES one by one>]
do
sh run.sh <TOKEN>
done

please provide the logic for seperating NAMES token and then calling run.sg with each token ????



Quote:
Originally Posted by vino
Can you show us what you have ? Perhaps, we can guide you better when we see the script.
# 4  
Old 07-16-2007
Quote:
Originally Posted by skyineyes
#!/user/bin
NAMES=`ls *.txt`
echo $NAMES

The content of this NAMES variable are TOKENS seperated by spaces.

i want to pass each token to another script called run.sh as follows:


while [<ALL tokens in $NAMES one by one>]
do
sh run.sh <TOKEN>
done

please provide the logic for seperating NAMES token and then calling run.sg with each token ????
You would be better off with using a for loop
Code:
NAMES=`ls *.txt`
echo $NAMES
for file in $NAMES
do
  sh run.sh $file
done

or better yet
Code:
for file in *.txt
do
  sh run.sh $file
done

# 5  
Old 07-16-2007
Thanks.

Its working !!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell file if condition setting start and end dates

I have shell file that has the following logic, i am new to shell programming. What does process month $1 do? I am assuming that the below dates go back three months from sysdate month. is it right : curr_month=`date +%Y%m` Beg_o_time=`date -d "2012/03/01" +%Y%m` Process_months=$1... (1 Reply)
Discussion started by: cplusplus1
1 Replies

2. UNIX for Dummies Questions & Answers

Bash condition test at the end of string

I want to check (using bash condition test function) if string contains three spaces, ignoring last three spaces at the end of string. string_to_report='foo bar foo bar ' string_to_ignore='foo bar ' (8 Replies)
Discussion started by: useretail
8 Replies

3. Shell Programming and Scripting

If condition help required

I have a if condition it checks its pid exist it means it is running, otherwise not running. I am checking with ps x=`ps -fu myuserid|grep java| |grep -v grep | awk '{print $2}'` if then ............ Above code is giving integer error, because currently process of java is... (4 Replies)
Discussion started by: learnbash
4 Replies

4. Shell Programming and Scripting

While Loop with if else condition

Hi, I was trying to write a shell script which reads csv file and sends mail in html format along with tables. Hope i have completed 1st part , but while sending mail i was trying to highlight some rows in the table based on the egrep outcome. If the string exists in line/INPUT, i am trying to... (4 Replies)
Discussion started by: varmas424
4 Replies

5. Shell Programming and Scripting

Help with extract info if fulfill condition required

Input file (4 DATA record shown in this case): DATA AA0110 ACCESSION AA0110 VERSION AA0110 GI:157412239 FEATURES Location/Qualifiers length 1..1170 1..1700 /length="1170" position ... (5 Replies)
Discussion started by: perl_beginner
5 Replies

6. Shell Programming and Scripting

Print required values at end of the file by using AWK

I am looking help in awk, quick overview. we will get feed from external system . The input file looks like below. Detail Id Info Id Order Id STATUS Status Date FileDetail 99127942 819718 CMOG223481502 PR 04-17-2011 06:01:34PM... (7 Replies)
Discussion started by: dvrbabu
7 Replies

7. Shell Programming and Scripting

Use of -z in while loop condition

Hi, Could you please tell what is the meaning of -z in while loop condition. For example, while ; do echo "*** Enter the age " readage (3 Replies)
Discussion started by: vidyaj
3 Replies

8. Shell Programming and Scripting

if condition in a while loop

Gurus, I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error. #!/bin/ksh . /home/.i_env ... (14 Replies)
Discussion started by: svajhala
14 Replies

9. Programming

Why is required to leave an empty line at the end of a C program?

I know it looks like a stupid question, but i really wanna know the reason. Actually, i think it's because the c compiler will detect it as the end of file "EOF" of the program, but, am i wrong? because it compiles it anyway, but keep showing warnings like "no new line at the end of file". I... (8 Replies)
Discussion started by: semash!
8 Replies

10. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies
Login or Register to Ask a Question