[SOLVED]-Syntax error puzzling me

Forum rules
Before you post please read how to get help
Post Reply
greywolf
Level 1
Level 1
Posts: 27
Joined: Thu Sep 19, 2013 7:20 pm

[SOLVED]-Syntax error puzzling me

Post by greywolf » Mon Dec 11, 2017 11:03 pm

I am sure there is a very simple explanantion to this problem that is just eluding my weary mind at present? This line in a bash script is not parsing - I think I may have the right bracket in the wrong place? The error message is "couldn't parse this test expression".

I would appreciate it if anyone could offer a solution to the syntax:

Code: Select all

if [ 0 -lt ${size} 2>> ${Trash} ] ; then
cheers,
greywolf.
Last edited by greywolf on Tue Dec 12, 2017 7:27 am, edited 1 time in total.
It is about the Dragons - it was always about the Dragons!

rene
Level 7
Level 7
Posts: 1706
Joined: Sun Mar 27, 2016 6:58 pm

Re: Syntax error puzzling me

Post by rene » Tue Dec 12, 2017 1:27 am

greywolf wrote:The error message is "couldn't parse this test expression".
I'm finding that error message only in the context of the "shellcheck" tool, available online at https://www.shellcheck.net/. If indeed you are referring to that you should've specified such: it's not standard and apparently just trips over your stderr redirection inside of the brackets.

As I personally also did even though it works with both bash and dash (i.e., /bin/sh). Also makes sense that it would, given a history of "[" as an actual external binary, but it's still weirdish: [ expr ] is another way of writing test expr; any redirection concerns the output of "test": is not part of the test expression and should as such be placed outside of the square brackets. Bash and dash accept it no doubt as an explicit compatibility issue with Olden Days but seems that "shellcheck" does not.

It's a random external tool...

greywolf
Level 1
Level 1
Posts: 27
Joined: Thu Sep 19, 2013 7:20 pm

Re: [SOLVED]-Syntax error puzzling me

Post by greywolf » Tue Dec 12, 2017 7:30 am

Thanks for the guidance - I found an old bash scriping guide I have - and it confirmed the re-direct stuff to be superfluous, as a re-direct of a comparison is not appropriate. Removed the offending piece and it works as expected.

greywolf.
It is about the Dragons - it was always about the Dragons!

Post Reply

Return to “Scripts & Bash”