English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Scripting (https://eab.abime.net/forumdisplay.php?f=117)
-   -   AmigaDos 1.3 Ask with User Input into Variable (https://eab.abime.net/showthread.php?t=103540)

Starfox 13 August 2020 10:37

AmigaDos 1.3 Ask with User Input into Variable
 
1 Attachment(s)
Hi,


i would like to code a Question asking about what Drive to use as source and the same as destination (df0: df1: etc..)



I use a normal Workbench 1.3 Shell Script executed over IconX.


My Problem is this Script won´t accept set or unset and requestchoice and my Workbench 1.3 Shell also.


It´s a script for Disksalv to make it easy to use and more comfortable.


In Picture i have the part of the code i coded to ask for Formatted Disk in Destination drive or not.



But how to save the user input into a variable and Ask a Question without only y and n ?

StingRay 13 August 2020 16:48

Code:

Echo "Which drive?"
Set >nil: drive ?
Echo $drive

Should do what you want.

Edit: Or not as I missed the "1.3" requirement.

Matt_H 13 August 2020 21:17

This isn’t a direct answer to your question, but I think DiskSalv can be controlled pretty well through project icons and tooltypes, so that might be another way to achieve what you’re trying to do.

malko 14 August 2020 00:50

@starfox : Adapt, shorten, optimize, etc... it to you needs ;)

https://i.ibb.co/vvD5DVW/Script.gif

Starfox 14 August 2020 09:21

Thanks to all this helps me very much :great

Starfox 15 August 2020 16:50

Additional Question:

Is there any way to Display 2 Variables in 1 Line or put 2 variables together ?

My destination is to Display "diksalv var1 var2"

Starfox 16 August 2020 14:25

I have created a solution for my Script.


Feel free to Optimize it.


Code:

.key ""
.bra {
.ket }
echo "***** Disksalv 1.42 Disketten Rettungs Tool ******"
echo ""
echo "** Disksalv rettet Daten von einer beschädigten **"
echo "** Quell-Diskette und kopiert diese auf eine    **"
echo "** frisch formatierte Ziel-Diskette.            **"

IF NOT EXISTS Disksalv
echo "Fehler Programm Disksalv nicht gefunden !"
echo "Programm wird beendet."
wait 1
ENDCLI
ENDIF

LAB Question
echo ""
echo "Bitte wählen Sie das Quell-Laufwerk und Ziel-Laufwerk"
echo "1 = QUELLE df0: ZIEL df1:"
echo "2 = QUELLE df1: ZIEL df0:"
echo "3 = QUELLE df1: ZIEL df2:"
echo "4 = QUELLE df2: ZIEL df1:"
echo "5 = QUELLE df0: ZIEL df2:"
echo "6 = QUELLE df2: ZIEL df0:"

SETENV >NIL: choice ?


IF $choice NOT VAL GT 0
echo "Falsche Eingabe bei der Auswahl des Quell und Ziel Laufwerks."
wait 1
SKIP BACK Question
ENDIF

IF $choice GE 7
echo "Falsche Eingabe bei der Auswahl des Quell und Ziel Laufwerks."
wait 1
SKIP BACK Question
ENDIF


IF $choice VAL EQ 1
ask "*N Die Ziel-Diskette vorher formatieren ? (y/n)"
IF WARN
disksalv df0: df1: FORMAT
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ELSE
disksalv df0: df1:
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ENDIF
ENDIF

IF $choice VAL EQ 2
ask "*N Die Ziel-Diskette vorher formatieren ? (y/n)"
IF WARN
disksalv df1: df0: FORMAT
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ELSE
disksalv df1: df0:
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ENDIF
ENDIF


IF $choice VAL EQ 3
ask "*N Die Ziel-Diskette vorher formatieren ? (y/n)"
IF WARN
disksalv df1: df2: FORMAT
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ELSE
disksalv df1: df2:
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ENDIF
ENDIF

IF $choice VAL EQ 4
ask "*N Die Ziel-Diskette vorher formatieren ? (y/n)"
IF WARN
disksalv df2: df1: FORMAT
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ELSE
disksalv df2: df1:
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ENDIF
ENDIF

IF $choice VAL EQ 5
ask "*N Die Ziel-Diskette vorher formatieren ? (y/n)"
IF WARN
disksalv df0: df2: FORMAT
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ELSE
disksalv df0: df2:
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ENDIF
ENDIF

IF $choice VAL EQ 6
ask "*N Die Ziel-Diskette vorher formatieren ? (y/n)"
IF WARN
disksalv df2: df0: FORMAT
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ELSE
disksalv df2: df0:
echo "Rettung der Diskette abgeschlossen."
echo "Programm wird geschlossen."
wait 5
ENDCLI
ENDIF
ENDIF


malko 17 August 2020 00:46

Quote:

Originally Posted by StingRay (Post 1420414)
Code:

Echo "Which drive?"
Set >nil: drive ?
Echo $drive

Should do what you want.

Edit: Or not as I missed the "1.3" requirement.

Redirecting the command to nil: to prevent the diplay of the "help" raised by the question mark while the variable name is provided is interesting. also working under 1.3 with SetEnv. thanks for the tip :)

malko 07 October 2021 14:06

for WB 34.(21|28|34)
 
While browsing a folder containing some files I stumbled across an 'HD install' script I made (WB 1.3 - not using the 'Installer' scripting language, only WB 1.3 commands).

The script was small and worked but I remember not being really happy with it. Especially because I wasn't able to use wanted variables so the script kind of 'forced' some choices...

It was of no importance but re-reading it made me think that a better solution could be found.
Thus, I tried to rewrite it with the goal of being able to use variables on this WB 1.3 script.

My main concern was to pass the variable to the 'copy' command. I tried some redirections, pipes but with no luck (maybe it's possible but my command was incorrect ?)
So I began to think about a workaround. After some thinking, a strange idea came to my mind... and it worked :spin

Here is my summarized solution :

Code:

[...]
;create the variable in ENV:SRC
if [...]
  setenv SRC "DF0:"
else
  if [...]
      setenv SRC [...]
  else
      if [...]
            setenv SRC [...]
      else
        if [...]
                    setenv SRC [...]
        endif
      endif
  endif
endif
[...]
;the following line is part of the solution
echo >t:cpdme "1CL//"
;create an intermediate script containing the 'copy' command which use the predefined variable
echo >t:cpdm "copy " NOLINE
getenv >>t:cpdm SRC
echo >>t:cpdm " TO {DEVICE}{PATH} ALL CLONE QUIET" NOLINE
;calling edit in 'stealth' mode to remove the linefeed that has been added by the getenv concatenation
edit FROM t:cpdm TO t:cpdm. WITH t:cpdme
delete t:cpdm t:cpdme
execute t:cpdm.
[...]

If you know how to natively use variables in a WB 1.3 script or have better ideas on how to use (redirect or pipe) them to WB 1.3 commands, please let us know :) .

Thomas Richter 07 October 2021 14:32

Quote:

Originally Posted by malko (Post 1510227)
[/code]If you know how to natively use variables in a WB 1.3 script or have better ideas on how to use (redirect or pipe) them to WB 1.3 commands, please let us know :) .

You can't, because the 1.3 shell does not have a clou about variables. The only place where environment variables (and only those) are expanded are as arguments of the "if" command, and only there because the "if" command does it itself. The 1.3 shell is completely unaware of the "$"-syntax to indicate variables.


If you want argument substitution, then "execute" is your other candidate which does that on a primitive "text-substitution" basis of the "arguments" passed into a script.

malko 07 October 2021 15:50

Thank you Thomas for the precisions.

BitD I have learnt the hard way, with a lot of frustration, that the 1.3 Shell was not able to 'expand' the "$<variable_name>" but in the other hand I always found strange that the 'Execute' command that is used to launch a script didn't implement such a parser.

Fortunately, BitD ARP for 1.3 addressed some of the 1.3 youth errors.

Thomas Richter 07 October 2021 17:24

Well, argument substitution works with execute already in 1.3, just that the syntax is different, namely <variable name>, not with $variable name. Which nicely conflicts with I/O redirection, and is perfectly inconsistent with how "if" handles variables in 1.3.

The joy of Tripos, what else to say?

malko 07 October 2021 18:13

Argument substitution of the parameters provided to the script (".key"), yes. Regarding the I/O redirection conflicts, you know that even the Commodore manual recommended the use of the ".bra {" & ".ket }". So no problem here.
But, even, don't forget the default value that can be given with the $ sign "{argument$default_value}" ;)

No, here my point is that it is strange that even a "{variable_name}" was not handled natively (thus allowing, inside scripts, the use of variable created with the 'setenv' command (and stored in ENV: by the system - or created manually in ENV: )).

But you are correct by saying that there is an inconsistency between the way "if" handle the $variable and the way "execute" handle the {argument}.


All times are GMT +2. The time now is 12:50.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.08629 seconds with 11 queries