1

I have this problem with this awk, that it works but I get the command not found error

for line in $(cat ${FILE_LIST_PROCES}); do 
    
    ARCHIVO=$line
    echo "[`date '+DATE: %m/%d/%y %H:%M:%S'`] - Validando script: "$ARCHIVO
    if [ ! -f $ARCHIVO ]; then
            echo "[`date '+DATE: %m/%d/%y %H:%M:%S'`] - ERROR -"
        exit ${ARCHIVO_NO_ENCONTRADO}
    else
        `gawk '{
            if (/GRANT/||/REVOKE/) 
                if (/EXECUTE/||/REFERENCES/||/TRIGGER/||/ALL PRIVILEGES/) 
                    print "1";
                else{
                    I=0;
                    while (I<=NF){
                        if ($I == "TO")
                            if ($++I !~ /^[^uU][0-9]{6};?$/)    
                                print "1";
                        I++
                    }
                }
            }' "$ARCHIVO"`
            if [[ $? -eq 0 ]];then
                $ARCHIVO >> $FILE_LIST_TMP  
            else 
                echo "[`date '+DATE: %m/%d/%y %H:%M:%S'`] - ERROR - "
                mv $ARCHIVO $FILE_ERRORES
            fi                         
    fi
done

with the following error when I echo 1, I don't understand what is the problem

./build.sh: line 80: 1: command not found
Gabriela
  • 11
  • 5

2 Answers2

0

Backticks are Command Substitution -- the contents of the backticks are executed in a subshell, and the shell replace the command substitution with the output. This is why echo "Right now it is $(date)" works as you expect.

If you do this:

echo before
`date`
echo after

Then, after the command substitution, the shell will try to run this:

echo before
Thu Jun 25 10:30:12 EDT 2020
echo after

And you see some error like Thu: command not found

TL;DR

You don't put backticks around every external command.


Also, prefer the $(...) form of command substitution -- it's easier to see and easier to nest.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
0

this somehow fix it:

 for line in $(cat ${FILE_LIST_PROCES}); do 
        
        ARCHIVO=$line
        echo "[`date '+DATE: %m/%d/%y %H:%M:%S'`] - Validando script: "$ARCHIVO
        if [ ! -f $ARCHIVO ]; then
                echo "[date '+DATE: %m/%d/%y %H:%M:%S'] - ERROR - archivo " ${ARCHIVO} " no encontrado"
            exit ${ARCHIVO_NO_ENCONTRADO}
        else
            iResult=`gawk '{
                if (/GRANT/||/REVOKE/) 
                    if (/EXECUTE/||/REFERENCES/||/TRIGGER/||/ALL PRIVILEGES/) 
                        print "1";
                    else{
                        I=0;
                        while (I<=NF){
                            if ($I == "TO")
                                if ($++I !~ /^[^uU][0-9]{6};?$/)    
                                    print "1";
                            I++
                        }
                    }
                }' "$ARCHIVO"`
                for i in $iResult
                do  
                    if [ $i -ne 0 ]; then
                    echo "[`date '+DATE: %m/%d/%y %H:%M:%S'`] - ERROR - Archivo con sentencia erronea"
                    exit ${ARCHIVO_NO_ENCONTRADO}
                    fi
                done                    
        fi
    done
Gabriela
  • 11
  • 5