If statement not working from php (www-data) user

hello, i have a problem with my script

#!/bin/bash
 linenum=$(grep -n -w somedata /usr/local/xx/xxx.txt |cut -f1 -d:);  
 if [ $linenum > 0 ] 
 then 
 linestart=$((linenum-1)); 
 linesend=$((linenum+3)); 
 sed -i "$linestart,$linesend d" /usr/local/xx/xxx.txt; 
fi

this script works fine from terminal but from php (exec_shell) i have this message ('permission denied'), when i remove 'if then fi' the script work fine, :confused::confused::confused:

Correct is

 if [ $linenum -gt 0 ]

The > 0 is a redirection to a file "0"! Bash handles it differently unless called with --posix.

1 Like

thank you sir :slight_smile: :slight_smile: :slight_smile:

Not even with --posix . It is not part of the POSIX specification.

Even so, most shells do support string comparison when the > or < is escaped, through their shell builtin

[ "$string1" \> "$string2 ]

This is not supported by the external test command, however, so in Bourne shell this will not work

--
But what is required here is a numerical comparison which requires the -gt operator, as stated before..

1 Like