1

I am creating the shell script that will take two condition first it will get all file name in and insert one by one in html field other for loop will get the count and it will used for auto increment in serial number.

I have written code like this

cnt=`find /optware/oracle/logs/20190311_JAVA/TEMP/  -type f | wc -l`
    for ((i in `ls -l /optware/oracle/logs/20190311_JAVA/TEMP/|grep -v ^$|awk '{print $9}` && a=1; a <= $cnt ; a++)) 
    do
    echo "  <tr> $a <td></td><td>$i</td></tr>" >>Temp.lst
    done

I am getting error as && a=1: arithmetic syntax error

Kindly help me with this issue.

0

3 Answers 3

1

You can't loop over an index+value pair directly in Bash. I would write this code as follows:

index=0
for path in /optware/oracle/logs/20190311_JAVA/TEMP/*
do
    echo "  <tr>${index}<td></td><td>${path}</td></tr>" >> Temp.lst
    ((++index))
done
Sign up to request clarification or add additional context in comments.

Comments

0

You're mixing up two looping constructs. You can use either one, but not both together.

for name [ [in [words …] ] ; ] do commands; done

and

for (( expr1 ; expr2 ; expr3 )) ; do commands ; done

Comments

0

The ((...)) should contain three arithmetic expressions. in is not an arithmetic operator. In fact, it's unclear what you're trying to achieve.

To nest two loops, specify each one with its own for:

for i in `ls -l /optware/oracle/logs/20190311_JAVA/TEMP/|grep -v ^$|awk '{print $9}` ; do
    for (( a = 1 ; a <= cnt ; a++ )) ; do
        echo "$i:$a"
    done
done

If you just need a counter, there's no need for the second loop:

a=1;
for i in `ls -l /optware/oracle/logs/20190311_JAVA/TEMP/|grep -v ^$|awk '{print $9}` ; do
    echo "$i:$a"
    (( ++a ))
done

1 Comment

the above query will return multiple output, what i want first to check how many file their in a directory suppose theiar are 10 file 10 will be the count and in other loop i will display each and and every file. the count will be used for auto increment like serial number in table. hope it should give you some idea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.