[SOLVED]-Syntax error puzzling me

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
greywolf
Level 1
Level 1
Posts: 30
Joined: Thu Sep 19, 2013 7:20 pm

[SOLVED]-Syntax error puzzling me

Post by greywolf »

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 LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
It is about the Dragons - it was always about the Dragons!
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Syntax error puzzling me

Post by rene »

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: 30
Joined: Thu Sep 19, 2013 7:20 pm

Re: [SOLVED]-Syntax error puzzling me

Post by greywolf »

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!
Locked

Return to “Scripts & Bash”