markjoe Posted June 10, 2008 Share Posted June 10, 2008 Here is the piece of code in question. if [ `rm "/raid/$purgeFile.mpg"` -eq 0 ] then echo "Deleted $purgeFile.mpg" else echo "Unable to Delete $purgeFile.mpg" fi I get an error stating: "Unary operator expected", and the else branch runs. Yet, the files seem to be deleted. I only say 'seem to be', because I did not confirm the files where there in the first place. But the list this is running through is way longer than the echos I get from the script, and if I run it again, I get nothing back. Do I have a simple syntax problem here? Obviously, I'm not Super Bash Guy here. Running on HP's Tru64 UNIX. Quote Link to comment https://forums.phpfreaks.com/topic/109609-solved-bash-error-but-seems-to-work-anyway/ Share on other sites More sharing options...
trq Posted June 10, 2008 Share Posted June 10, 2008 The $? variable holds the exit signal of the last executed command so.... rm "/raid/${purgeFile}.mpg" if [ "{$?}" -eq 0 ] then echo "Deleted ${purgeFile}.mpg" else echo "Unable to Delete ${purgeFile}.mpg" fi Quote Link to comment https://forums.phpfreaks.com/topic/109609-solved-bash-error-but-seems-to-work-anyway/#findComment-562579 Share on other sites More sharing options...
markjoe Posted June 11, 2008 Author Share Posted June 11, 2008 That did it, thanks alot. I thought the backticks would bring the returned code into the conditional. Quote Link to comment https://forums.phpfreaks.com/topic/109609-solved-bash-error-but-seems-to-work-anyway/#findComment-563398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.