set -options not working inside for loop?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting set -options not working inside for loop?
# 1  
Old 02-17-2011
set -options not working inside for loop?

I'm a beginner in shell scripting (I'm using ksh). I'm manipulating some files and I'm using set -A to transform each read line into a numeric array.
However, inside the 'for' loop the options of set (ie '-A') are not recognized (the vi editor doesn't highlight it and it doesn't work).

Where is my error?

My data.entry.* files are of the format:
Code:
   2 number_of_variables
-1.654824e+02    x1
-2.4685125e+01   x2

Code:
FILEIN="data.entry."   # I've got files named like data.entry.34
FILEOUT="global_entries"
 
files=`ls $FILEIN* | cut -d "." -f 3 | sort -n`
set -A F $files                      #THIS set -A works properly
FirstEvaluation=${F[0]}
echo $FirstEvaluation First_Evaluation_Number > $FILEOUT
 
for f in $files; do
   let "count=0"
   VarsArray=" "
   while read myline;
   do
 if (($count == 0));then 
    set -A WORDS $myline   # The -A is not recognized as a set option!?
    let "NumVars=${WORDS[0]}"
 elif (($count <= $NumVars));then
    set -A WORDS $myline     # The -A is not recognized as a set option!?
    VarX=${WORDS[0]}
           VarsArray=$VarsArray"    "$VarX
 else
    break
 fi
 ((count++))
   done < $FILEIN$f
 
   echo $VarsArray >> $FILEOUT 
done

# 2  
Old 02-17-2011
Code:
#!/usr/bin/ksh

Should be the first line of your script (if you want make sur you run it in ksh)
of course adapt the path if necessary

---------- Post updated at 12:55 PM ---------- Previous update was at 12:32 PM ----------

instead of:
Code:
if (($count == 0));then
...
elif (($count <= $NumVars));then

try
Code:
if (( $count == 0 ));then
...
elif (( $count <= $NumVars ));then

If you have some error message when running your script, please post them
# 3  
Old 02-17-2011
The line
Code:
#!bin/ksh

was already in the code, I forgot to post it...

I used this file as a test:
Code:
                                          2 variables
                     -1.992929132651970e+00 x1
                     -2.621936892448895e-02 x2

and when running the shell i get:

Code:
./EvalShell.sh[43]: set: -1: unknown option
./EvalShell.sh[43]: set: -.: unknown option
./EvalShell.sh[43]: set: -9: unknown option
./EvalShell.sh[43]: set: -9: unknown option
./EvalShell.sh[43]: set: -2: unknown option
./EvalShell.sh[43]: set: -9: unknown option
./EvalShell.sh[43]: set: -2: unknown option
./EvalShell.sh[43]: set: -9: unknown option
./EvalShell.sh[43]: set: -1: unknown option
./EvalShell.sh[43]: set: -3: unknown option
./EvalShell.sh[43]: set: -2: unknown option
./EvalShell.sh[43]: set: -6: unknown option
./EvalShell.sh[43]: set: -5: unknown option
./EvalShell.sh[43]: set: -1: unknown option
./EvalShell.sh[43]: set: -9: unknown option
./EvalShell.sh[43]: set: -7: unknown option
./EvalShell.sh[43]: set: -0: unknown option

Line 43 corresponds to the line of the second "set -A WORDS $myline" in the for loop.
It seems the input for the set options are the digits of the number in the entry test file... I have no idea why this happens!
# 4  
Old 02-17-2011
Code:
#!bin/ksh

?
or
Code:
#!/bin/ksh

?

Did you post your whole script or just a part of it ???

The error you get suggest a problem line 43 and what you posted dooesn't exceed 38 lines
# 5  
Old 02-17-2011
Yes, it is actually
Code:
 
#!/bin/ksh

That's the whole script (without comments)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Set, setenv or export? Confused between three options

Hi Experts, Need your help in understanding the commands to setup the environment variables in hp-ux. Beleive need to use either set,setenv or export. I am confused between above three options, when to use which option? On command line, I have tried both set and setenv but couldn't... (7 Replies)
Discussion started by: userexperience
7 Replies

2. Shell Programming and Scripting

If loop inside function not working.

check_deplver () { dir=/abc/def/ghi if ssh -o StrictHostKeychecking=no $1 "" 2> /dev/null then echo " output is " ssh -o StrictHostKeychecking=no $1 "ls -lrt $dir | grep -i abc" 2> /dev/null else echo " directory not presnt" fi } This is not working. But... (7 Replies)
Discussion started by: NarayanaPrakash
7 Replies

3. Shell Programming and Scripting

string comparison not working inside while loop

The string comparison highlighted below is not working fine. Please help: while read line do # Get File name by deleting everything that preceedes and follows Filename as printed in cvs status' output f_name=`echo $line | sed -e 's/^File://' -e 's/ *Status:.*//' | awk '{print $NF}'` ... (4 Replies)
Discussion started by: sudvishw
4 Replies

4. Shell Programming and Scripting

String comparison not working inside while loop

Hi, In the code included below, the string comparision is not working fine. Please help while (( find_out >= i )) do file=`head -$i f.out|tail -1` dir=`dirname $file` cd $dir Status="" if ; then Status=`cvs -Q status... (3 Replies)
Discussion started by: sudvishw
3 Replies

5. UNIX for Advanced & Expert Users

Vi set options

Does know where I can find what ALL of the set options do in vi? I can't find it anywhere in vi's man pages or help files. I know about :set all but a lot of the options I have no clue what they do. (3 Replies)
Discussion started by: cokedude
3 Replies

6. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

7. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

8. Shell Programming and Scripting

String handling is not working inside if loop

Hi All, I am comparing two strings inside an if condition if the strings are same then it should go inside the loop else it should execute code given in else part. But there is a but inside my script Even if the if condition is true it is not going inside the loop also it is executing... (4 Replies)
Discussion started by: usha rao
4 Replies

9. Shell Programming and Scripting

looping a array inside inside ssh is not working, pls help

set -A arr a1 a2 a3 a4 # START ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS integer j=0 for loop in ${arr} do printf "array - ${arr}\n" (( j = j + 1 )) j=`expr j+1` done EOS # END ========= this is not giving me correct output. I... (5 Replies)
Discussion started by: reldb
5 Replies

10. HP-UX

large file options is set

Can someone tell me the right or exact syntax to check if the large file options is set on a filesystem Thanks! (2 Replies)
Discussion started by: catwomen
2 Replies
Login or Register to Ask a Question