3

I am trying to make the following double do while boucle:

#!/bin/bash

#Router cisco
ls equipos/ |grep cisco |tr ' ' '\n' >> $$.cisco.tmp

config="/Users/joseluis/Desktop/prueba/config"

echo "XXXXXXXXXX ficheros"
echo $$.cisco.tmp
echo $config
echo "XXXXXXXXXX contenido tmp"
cat $$.cisco.tmp
echo "XXXXXXXXXX contenido config"
cat $config
echo "XXXXXXXXXX"


while IFS= read -r router
do
    echo "LOOP"
    echo $router

    echo "equipos/$router"

    while IFS= read -r config
    do

        grep "$config" "equipos/$router" &> /dev/null

            if [ $? == "1" ]; then
                echo "$router -> $config"
            fi  
    echo "---"
    echo "$config"
    echo "---"


    done <"$config"

done <"$$.cisco.tmp"

rm $$.cisco.tmp

$ ./script.sh 
XXXXXXXXXX ficheros
7405.cisco.tmp
/Users/joseluis/Desktop/prueba/config
XXXXXXXXXX contenido tmp
cisco.1
cisco.2
XXXXXXXXXX contenido config
a
1
XXXXXXXXXX
LOOP
cisco.1
equipos/cisco.1
---
a
---
cisco.1 -> 1
---
1
---
LOOP
cisco.2
equipos/cisco.2
./script.sh: line 41: : No such file or directory

But when i tried to evaluate the second condition i receive the "No such file or directory" error, but that is no true, the file exists. Why i receive this error? Can somebody help me?

Thank you.

BR.

2

The error you're receiving is due to the fact you're using the same name (config) for two different variables.

  1. The variable with the file name read in the inner loop.
  2. The variable that receives each line from that file.

So, after the first time the inner loop ends, the old variable config now has the last line of the config file, and not its path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.