Ticket #599 (Open)Thu Jun 01 20:55:21 UTC 2023
IF command doesn't care if the THEN is in a string
Reported by: | Simon Willcocks (1499) | Severity: | Minor |
Part: | RISC OS: General | Release: | |
Milestone: | Status | Open |
Details by Simon Willcocks (1499):
*if " if this doesn’t work then this is a bug" <> “nomatch” then echo Hello
String not recognised
*if " if this doesn’t work thexn this is a bug" <> “nomatch” then echo Hello
Hello
It’s only a problem if the “then” is surrounded by spaces, so not if it’s part of a variable name.
Changelog:
Modified by Sprow (202) Sat, June 03 2023 - 13:06:30 GMT
- Summary changed from IF command doesn't care if the THIS is in a string to IF command doesn't care if the THEN is in a string
- Part changed from Unspecified to RISC OS: General
Modified by Stuart Painting (5389) Sat, June 03 2023 - 19:07:19 GMT
A partial workaround is to put the string in a system variable and surround the system variable with quotes in the IF statement. For example:
set my$test " if this doesn’t work then this is a bug"
if “<my$test>” <> “nomatch” then echo Hello
This only works on RISC OS 5.29 builds dated 11 February 2021 and later (i.e. builds that include the fix for the ‘System variable containing a " character’ bug).
Modified by Stuart Painting (5389) Sat, June 03 2023 - 19:57:28 GMT
Whoops, schoolboy error. Using a system variable does in fact work as far back as RISC OS 3.7, and should work for all RISC OS versions.