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
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
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!
We have the following statement in a bash script running on AIX 7.2:
[ -n "$(grep \"^$2=\" \"$1\" 2>/dev/null)" ]
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 348 |
Nodes: | 16 (2 / 14) |
Uptime: | 87:52:49 |
Calls: | 7,609 |
Files: | 12,783 |
Messages: | 5,681,027 |