AmigaOS DOS commands

A forum for general AmigaOS 4.x support questions that are not platform-specific
User avatar
Amigo1
Posts: 221
Joined: Sun Jan 01, 2012 3:32 pm

AmigaOS DOS commands

Post by Amigo1 »

Hi all,

I am trying to infect my niece with the Amiga fever :D and testing a script from the AmigaOS 3.1 DOS Guide.
it's only an excerpt from the script:

Code: Select all

.KEY loop
.BRA {
.KET }

IF NOT {loop}
	ECHO "Enter a number"
	ECHO "and press enter " NOLINE
	SETENV >NIL: loop{$$} ?
ELSE
	ECHO >ENV:loop{$$} {loop}
ENDIF
ECHO "The number is $loop{$$}"
UNSETENV loop{$$}
The script works as described in the Guide book on AmigaOS 3.1 and AmigaOS 3.1.4.1 but the IF command
gives an error on AmigaOS 4.1 Final Edition Update 1 and the following error appears on screen if I provide
a number right when issuing the command:

8.RAM Disk:> execute smalltest 4
IF: required argument missing
8.RAM Disk:> execute smalltest
Enter a number
and press enter 4
The number is 4
8.RAM Disk:>


I modified the "IF" part as the following

Code: Select all

IF {loop} NOT CONTAINS ""
now it works on AmigaOS 4.1 Final Edition Update 1 but not on AmigaOS 3.1.4.1 and less

So is this difference on purpose?

Thanks for reading and the work behind the curtains. :)
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: AmigaOS DOS commands

Post by thomasrapp »

You should keep in mind that the argument substitution in scripts is a textual one. So if you run the script without any arguments the line IF NOT {loop} becomes IF NOT. This does not make any sense. To be honest even if you supply arguments, for example "4", it still makes no sense for me. What shall IF NOT 4 do?

I would use something like this:

Code: Select all

IF "{loop}" NOT EQ ""
   ECHO "argument given"
ELSE
   ECHO "no argument given"
ENDIF
or like this:

Code: Select all

IF "{loop}" EQ ""
   SET loop 0
ELSE
   SET loop {loop}
ENDIF

IF $loop EQ VAL 0
   ECHO "Please enter number"
...
ENDIF

...
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: AmigaOS DOS commands

Post by nbache »

Furthermore, CONTAINS (and MATCHES) came as new in the Shell in v. 50.42 (8.1.2004), i.e. they only exist in OS4.

Best regards,

Niels
User avatar
Amigo1
Posts: 221
Joined: Sun Jan 01, 2012 3:32 pm

Re: AmigaOS DOS commands

Post by Amigo1 »

thomasrapp wrote: Tue Jun 02, 2020 4:13 pm You should keep in mind that the argument substitution in scripts is a textual one. So if you run the script without any arguments the line IF NOT {loop} becomes IF NOT. This does not make any sense. To be honest, even if you supply arguments, for example, "4", it still makes no sense for me.
I see what you mean and I share your view. As I said, the example was taken from the official AmigaOS 3.1 DOS Guide, and I was just wondering about the different outcome of the script.

I interpreted the statement as below, and maybe it is how the author of the text and whoever wrote the "IF" command back then, might have thought of it, oh, and btw, read it and imagine Yoda from StarWars speaking: ;)

Code: Select all

IF NOT (given the argument) {loop} (was, then)
	DOWHATEVERCOMESNEXT
ELSE (if the argument given was)
	DOTHISINSTEAD
ENDIF 
and then
What shall IF NOT 4 do?
IF NOT 4 (yes, it's true: because 4 is 4; it is using the reflexive relation, if no 4 was given, then this would be false)

Well, that is how I tried to make sense of it anyway. Now, your examples are more of an immediate logic :) hopefully, "IF" is going to be fixed on AmigaOS 3.2 too, so the experience is more cohesive.

About your examples: thanks. The second example is ehm.. prettier but it did not work right away,

Code: Select all

3.RAM Disk:> ram:testscript5 0
argument given
IF: wrong number of arguments
3.RAM Disk:>
I had to swap the EQ and VAL arguments to "IF $loop VAL EQ 0"; should IF be more tolerant?

And there is a small cosmetic bug when invoking "IF ?" in the shell btw. I'll post that as a reply to nbache. :)
User avatar
Amigo1
Posts: 221
Joined: Sun Jan 01, 2012 3:32 pm

Re: AmigaOS DOS commands

Post by Amigo1 »

nbache wrote: Tue Jun 02, 2020 5:50 pm Furthermore, CONTAINS (and MATCHES) came as new in the Shell in v. 50.42 (8.1.2004), i.e. they only exist in OS4.

Best regards,

Niels
Hi,

I noticed the additional options as well, thanks for pointing that out. :)
There is a small cosmetic bug when invoking "IF ?" in the shell:

3.RAM Disk:> if ?
NOT/S,WARN/S,ERROR/S,FAIL/S,,EQ/K,GT/K,GE/K,LT/K,LE/K,MATCHES/K,CONTAINS/K,CASE/S,VAL/S,EXISTS/K,SET/K,NOREQ/S:


after the FAIL/S keyword there is a double comma.
Also, the help file for IF would surely be happy with an overhaul. Maybe I can take some work off someone, here a version with all the options listed.

Code: Select all

   NAME
	IF - Evaluate conditional operations in script files.

   FORMAT
	IF [NOT] [WARN] [ERROR] [FAIL] [<string> EQ|GT|GE|MATCHES|CONTAINS
	   <string>] [CASE] [VAL] [EXISTS <filename>] [SET <variable name>]
	   [NOREQ]

   TEMPLATE
	NOT/S,WARN/S,ERROR/S,FAIL/S,EQ/K,GT/K,GE/K,LT/K,LE/K,MATCHES/K,CONTAINS/K,
	CASE/S,VAL/S,EXISTS/K,SET/K,NOREQ/S

   PATH
	Internal

   FUNCTION
	In a script file, IF, when its conditional is true, carries out all
	the subsequent commands until an ENDIF or ELSE command is found. When
	the conditional is not true, execution skips directly to the ENDIF or
	to an ELSE. The conditions and commands in IF and ELSE blocks can
	span more than one line before their corresponding ENDIFs.

	Following are some of the ways you can use the IF, ELSE, and ENDIF
	commands:

	    IF <condition>    IF <condition>    IF <condition>
	    <command(s)>      <command(s)>      <command(s)>
	    ENDIF             ELSE              IF <condition>
	                      <command(s)>      <command(s)>
	                      ENDIF             ENDIF
	                                        ENDIF

	ELSE is optional, and nested IFs jump to the nearest ENDIF.

	The additional keywords are as follows:

	    NOT              Reverses the interpretation of the result.

	    WARN             True if previous return code is greater than or
	                     equal to 5.

	    ERROR            True if previous return code is greater than or
	                     equal to 10; only available if you set FAILAT to
	                     greater than 10.

	    FAIL             True if previous return code is greater than or
	                     equal to 20; only available if you set FAILAT to
	                     greater than 20.

	    <a> EQ <b>       True if the text of a and b is identical
	                     (disregarding case).

	    <a> GT <b>       True if the first letter of the text a is later 
	                     in the alphabet than the first letter of text b.

	    <a> GE <b>       True if the first letter of the text a is later 
	                     in the alphabet or equal than the first letter 
	                     of text b.

	    <a> LT <b>       True if the first letter of the text a is earlier 
	                     in the alphabet than the first letter of text b.

	    <a> LE <b>       True if the first letter of the text a is earlier 
	                     in the alphabet or equal than the first letter 
	                     of text b.

	    MATCHES          Compares the strings by using whildcard pattern,
	                     see examples below.

	    CONTAINS         Performs non case-sensitive substring searches, 
	                     unless CASE option is used. See examples below.

	    CASE             Enables case-sensitive substring search.

	    VAL              Enables numberic comparison. Must be given after
	                     the comparative keyword.

	    EXISTS <file>    True if the file exists.

	    SET <variable>   True if the environment variable is set (i.e.
	                     if it exists).

	    NOREQ            Do not show a requester window prompting the
	                     user to insert a disk if the 'EXISTS' test
	                     refers to a file on a volume which is not
	                     available at the moment.


	If more than one of the three condition-flag keywords (WARN, ERROR,
	FAIL) are given, the one with the lowest value is used.

	IF supports the GT (greater than) and GE (greater than or equal to)
	comparisons. Normally, the comparisons are performed as string
	comparisons. However, if the VAL option is specified, the comparison
	is a numeric comparison.

	A comparison can also be performed by using AmigaDOS wildcard
	patterns, e.g. "IF $drive_name MATCHES (dh0:|dh1:|dh2:)".
	Substring searches are supported through the "CONTAINS" keyword,
	e.g. "IF $volume_name CONTAINS :". The comparison in both cases
	is not case-sensitive. To enforce a case-sensitive comparison,
	use the "CASE" keyword.

	NOTE: You can use NOT GE for LT and NOT GT for LE.

	You can use local or global variables with IF by prefacing the
	variable name with a $ character.

   EXAMPLES
	    IF EXISTS Work/Prog
	        TYPE Work/Prog
	    ELSE
	        ECHO "It's not here"
	    ENDIF

	If the file Work/Prog exists in the current directory, then AmigaDOS
	displays it. Otherwise, AmigaDOS displays the message It's not here
	and continues after the ENDIF.
	    IF ERROR
	        SKIP errlab
	    ENDIF
	    ECHO "No error"
	    LAB errlab

	If the previous command produced a return code greater than or equal
	to 10 then AmigaDOS skips over the ECHO command to the errlab label.

   SEE ALSO
	EXECUTE, FAILAT, LAB, QUIT, SKIP
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: AmigaOS DOS commands

Post by nbache »

Amigo1 wrote: Wed Jun 03, 2020 2:36 pmThere is a small cosmetic bug when invoking "IF ?" in the shell:

3.RAM Disk:> if ?
NOT/S,WARN/S,ERROR/S,FAIL/S,,EQ/K,GT/K,GE/K,LT/K,LE/K,MATCHES/K,CONTAINS/K,CASE/S,VAL/S,EXISTS/K,SET/K,NOREQ/S:


after the FAIL/S keyword there is a double comma.
Yeah, that looks odd. It is also in the template section of the doc. Not sure if there's a point about that or it's just an oversight. The thing is, the template is actually used to parse the arguments, so I doubt it really is only cosmetic. We'll see if a developer can explain it.
Also, the help file for IF would surely be happy with an overhaul. Maybe I can take some work off someone, here a version with all the options listed.
Thanks ;-).

Just to summarize:

- You removed the extra comma and added LT and LE in the template.

- You added the sections about GT, GE, LT, LE, MATCHES, CONTAINS, CASE, and VAL to the list of additional keywords (they are already explained further down, but of course it makes sense to have them in the list).

- You swapped the sections for SET and NOREQ - was there a reason for that?

- You removed a blank line before the second example in the EXAMPLES section - was there a reason for that?

Anything I missed?

Thanks for the input.

Best regards,

Niels
User avatar
thomasrapp
Posts: 310
Joined: Sat Jun 18, 2011 11:22 pm

Re: AmigaOS DOS commands

Post by thomasrapp »

nbache wrote: Wed Jun 03, 2020 3:14 pmYeah, that looks odd.
It might look odd, but it's perfectly legal. It's just a positional parameter without a name. It only means the user is not able to move this parameter into another position by specifying the keyword because there is no keyword for it.

As an example in

IF "a" EQ "b"

"a" is the unnamed parameter and "b" is the parameter named EQ. EQ must be specified using its keyword because it has the /K attribute.

If you remove the comma, it will break the IF command.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: AmigaOS DOS commands

Post by nbache »

thomasrapp wrote: Wed Jun 03, 2020 5:20 pm
nbache wrote: Wed Jun 03, 2020 3:14 pmYeah, that looks odd.
It might look odd, but it's perfectly legal. It's just a positional parameter without a name. It only means the user is not able to move this parameter into another position by specifying the keyword because there is no keyword for it.
Thanks, Thomas, just the explanation I needed to jog my memory :-).

So we should keep the double comma also in the doc.

Best regards,

Niels
User avatar
Amigo1
Posts: 221
Joined: Sun Jan 01, 2012 3:32 pm

Re: AmigaOS DOS commands

Post by Amigo1 »

thomasrapp wrote: Wed Jun 03, 2020 5:20 pm
nbache wrote: Wed Jun 03, 2020 3:14 pmYeah, that looks odd.
It might look odd, but it's perfectly legal. It's just a positional parameter without a name. It only means the user is not able to move this parameter into another position by specifying the keyword because there is no keyword for it.

As an example in

IF "a" EQ "b"

"a" is the unnamed parameter and "b" is the parameter named EQ. EQ must be specified using its keyword because it has the /K attribute.

If you remove the comma, it will break the IF command.
A very important comma indeed. Thanks for the explanation! :)
User avatar
Amigo1
Posts: 221
Joined: Sun Jan 01, 2012 3:32 pm

Re: AmigaOS DOS commands

Post by Amigo1 »

nbache wrote: Wed Jun 03, 2020 3:14 pm
Just to summarize:

- You removed the extra comma and added LT and LE in the template.
Correct. But I read Thomas' reply, so the comma has a reason to be there.
- You added the sections about GT, GE, LT, LE, MATCHES, CONTAINS, CASE, and VAL to the list of additional keywords (they are already explained further down, but of course it makes sense to have them in the list).
Correct, I'm pleased you also think it makes sense to have them in the list. I also added SET to the list.
- You swapped the sections for SET and NOREQ - was there a reason for that?
The reason was to have the same order in the list as in the template. But there might be a better reason why they are in the current order. If so, I'd like to learn something new. :)
- You removed a blank line before the second example in the EXAMPLES section - was there a reason for that?
No reason for that, other than inadvertence, must have happened when I pasted the text and somehow I have deleted a line, the draft I have on my Amiga still hast the line.
Anything I missed?
The SET keyword in the list, and the typo in the VAL explanation: "numberic comparison" doesn't seem right. But then that's all I did.
Thanks for the input.
You are welcome, thanks for reading. :)

Best regards
Post Reply