• extra apostrophe in bash script

    From Burkhard Schultheis@21:1/5 to All on Thu Jul 19 16:07:27 2018
    We have the following statement in a bash script running on AIX 7.2:

    [ -n "$(grep \"^$2=\" \"$1\" 2>/dev/null)" ]

    During run, $2 gets the value nagios_retcode= and $1 gets /var/lib/ibm72dev_backup_state.txt.

    This statement does not work because the resulting line looks like

    grep '"^nagios_retcode="' '"/var/lib/ibm72dev_backup_state.txt"'

    On Linux it does work, but not on AIX. Where does the extra apostrophes
    come from? And how to avoid it?

    Thanks in advance for your help!

    Regards
    Burkhard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Burkhard Schultheis@21:1/5 to All on Thu Jul 19 16:50:38 2018
    Am 19.07.2018 um 16:07 schrieb Burkhard Schultheis:
    We have the following statement in a bash script running on AIX 7.2:

    [ -n "$(grep \"^$2=\" \"$1\" 2>/dev/null)" ]

    During run, $2 gets the value nagios_retcode= and $1 gets /var/lib/ibm72dev_backup_state.txt.

    This statement does not work because the resulting line looks like

    grep '"^nagios_retcode="' '"/var/lib/ibm72dev_backup_state.txt"'

    On Linux it does work, but not on AIX. Where does the extra apostrophes
    come from? And how to avoid it?

    Thanks in advance for your help!

    Regards
    Burkhard

    You can try the following script:

    #!/bin/bash

    P1="^nagios_update="
    P2="/var/lib/ibm72dev_backup_state.txt"
    echo "P1: $P1, P2: $P2"
    [ -n "$(grep \"^$P1=\" \"$P2\" 2>/dev/null)" ]
    RC=$?
    echo "RC: $RC"
    if [ $RC -ne 0 ]
    then
    echo "does not work"
    else
    echo "OK"
    fi

    On my AIX system it gives "does not work, P1 and P2 are shown without
    any quotes.

    Regards
    Burkhard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Burkhard Schultheis@21:1/5 to All on Thu Jul 19 20:38:46 2018
    Am 19.07.2018 um 16:50 schrieb Burkhard Schultheis:
    Am 19.07.2018 um 16:07 schrieb Burkhard Schultheis:
    We have the following statement in a bash script running on AIX 7.2:

    [ -n "$(grep \"^$2=\" \"$1\" 2>/dev/null)" ]

    During run, $2 gets the value nagios_retcode= and $1 gets
    /var/lib/ibm72dev_backup_state.txt.

    This statement does not work because the resulting line looks like

    grep '"^nagios_retcode="' '"/var/lib/ibm72dev_backup_state.txt"'

    On Linux it does work, but not on AIX. Where does the extra
    apostrophes come from? And how to avoid it?

    Thanks in advance for your help!

    Regards
    Burkhard

    You can try the following script:

    #!/bin/bash

    P1="^nagios_update="
    P2="/var/lib/ibm72dev_backup_state.txt"
    echo "P1: $P1, P2: $P2"
    [ -n "$(grep \"^$P1=\" \"$P2\" 2>/dev/null)" ]

    [ -n "$(grep \"$P1\" \"$P2\" 2>/dev/null)" ]

    RC=$?
    echo "RC: $RC"
    if [ $RC -ne 0 ]
    then
            echo "does not work"
    else
            echo "OK"
    fi


    Regards
    Burkhard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Burkhard Schultheis@21:1/5 to All on Fri Jul 20 10:07:41 2018
    Am 19.07.2018 um 16:07 schrieb Burkhard Schultheis:
    We have the following statement in a bash script running on AIX 7.2:

    [ -n "$(grep \"^$2=\" \"$1\" 2>/dev/null)" ]

    During run, $2 gets the value nagios_retcode= and $1 gets /var/lib/ibm72dev_backup_state.txt.

    This statement does not work because the resulting line looks like

    grep '"^nagios_retcode="' '"/var/lib/ibm72dev_backup_state.txt"'

    On Linux it does work, but not on AIX. Where does the extra apostrophes
    come from? And how to avoid it?

    Thanks in advance for your help!


    In the meantime we have solved the problem: :-)

    grep_result=$(grep "^$2=" "$1")
    [ -n "$grep_result" ]

    Regards
    Burkhard

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lorinczy Zsigmond@21:1/5 to Burkhard Schultheis on Sun Jul 29 10:25:03 2018
    On 07/19/2018 04:07 PM, Burkhard Schultheis wrote:
    We have the following statement in a bash script running on AIX 7.2:

    [ -n "$(grep \"^$2=\" \"$1\" 2>/dev/null)" ]

    Just for the record: the \backslashes should be removed:
    [ -n "$(grep "^$2=" "$1" 2>/dev/null)" ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)