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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement not working from php (www-data) user
# 1  
Old 06-20-2016
If statement not working from php (www-data) user

hello, i have a problem with my script

Code:
#!/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, SmilieSmilieSmilie
# 2  
Old 06-20-2016
Correct is
Code:
 if [ $linenum -gt 0 ]

The > 0 is a redirection to a file "0"! Bash handles it differently unless called with --posix.
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 06-20-2016
Quote:
Originally Posted by MadeInGermany
Correct is
Code:
 if [ $linenum -gt 0 ]

The > 0 is a redirection to a file "0"! Bash handles it differently unless called with --posix.
thank you sir Smilie Smilie Smilie
# 4  
Old 06-20-2016
Quote:
Originally Posted by MadeInGermany
Correct is
Code:
 if [ $linenum -gt 0 ]

The > 0 is a redirection to a file "0"! Bash handles it differently unless called with --posix.
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
Code:
[ "$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..

Last edited by Scrutinizer; 06-20-2016 at 05:19 PM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read statement not working

hello guys, i am having the below piece of code error () { echo"Press y /n" read ans case $ans in y) main;; n) exit esac } In the abve code, read statement is not working i.e not waiting for user to enter input. ,i tested exit status its 1. could anyone help me to do this ... (11 Replies)
Discussion started by: mohanalakshmi
11 Replies

2. Debian

Help request. FTP user to var/www/html

Hi all. I appologise this is my first post, I will gladly have a further look around to see if this has been posted elsewhere, but so far it has not, or it doesnt quite explain in full what I need. If anyone here can help me out, I would really appreciate this. I want to make sure I do this... (1 Reply)
Discussion started by: Pinkfloyd
1 Replies

3. Shell Programming and Scripting

If statement is not working in KSH

#! /bin/ksh rm -f ./xyz file --- this line is working // Below any if stmt is not working. if then echo " blah blah " fi or I replaced above if with if then echo "dir exists" fi This is also not working. I am new to KSH. So can someone help why if stmt is not... (31 Replies)
Discussion started by: saggy9583
31 Replies

4. Shell Programming and Scripting

Cshell if statement not working

Hi .I am trying to check the first arguments =-s and the third =-d,but it doesnt work ,any idea why It gives me if: Missing file name Thanks #case -s and files if( $1 == "-s" && $3 != "-d" ) then echo "case s" endif (1 Reply)
Discussion started by: lio123
1 Replies

5. Shell Programming and Scripting

If statement is not working.

Hi. With the help of this group I have created a shell script to find the factorial of a number. OK. Then I got wild.;) I tried to put in a check to make sure the entry is a number. read num If )) then echo "This is not a valid number. Try again." fi while (( $var <= $num)) more... (5 Replies)
Discussion started by: Ccccc
5 Replies

6. UNIX for Dummies Questions & Answers

if statement not working as desired

Hello all, I am trying to write a post-commit hook script using bash script. What I am trying to do here is: Developers check in their files to a branch. I check the repository and based on the commit I email QA people. QA verifies and moves the files to a prod branch and email is sent... (1 Reply)
Discussion started by: kminkeller
1 Replies

7. UNIX for Dummies Questions & Answers

until statement not working

im trying to write an until statement which dont go onto the next stage until the user inputs a certain phrase. It is then stored in an array. Ive come up with this code so far but its not working and i dont know why. read in1 until do echo "Incorrect, try again" ... (2 Replies)
Discussion started by: strasner
2 Replies

8. Shell Programming and Scripting

If statement not working

I understand this question probably poses some child like stupidity, but I can't get this if statement to work for love or money. #!/bin/ksh echo "Input either 1 or 2" read Num if ; then echo "Message 1" if ; then echo "Message 2" else echo "false" fi $ ksh decisions Input either 1... (6 Replies)
Discussion started by: Hazmeister
6 Replies

9. Shell Programming and Scripting

find/if statement not working

Hi guys: I am trying to delete multiple files in a folder with different names. Below is the script that I was trying, but it doesn't work ************************** #!/bin/ksh DATE=`date '+20%y%m%d'` DEL_DIR=<dir where files have to be deleted> let DATE2=$(($DATE - 2)) let DATE1=$(($DATE... (12 Replies)
Discussion started by: geomonap
12 Replies
Login or Register to Ask a Question