English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System > Coders. Scripting

 
 
Thread Tools
Old 13 August 2020, 10:37   #1
Starfox
Registered User
 
Join Date: Aug 2020
Location: Germany
Posts: 18
AmigaDos 1.3 Ask with User Input into Variable

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 ?
Attached Thumbnails
Click image for larger version

Name:	workbench1-real-2008131033-01.png
Views:	347
Size:	9.4 KB
ID:	68470  
Starfox is offline  
Old 13 August 2020, 16:48   #2
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Code:
Echo "Which drive?"
Set >nil: drive ?
Echo $drive
Should do what you want.

Edit: Or not as I missed the "1.3" requirement.
StingRay is offline  
Old 13 August 2020, 21:17   #3
Matt_H
Registered User
 
Matt_H's Avatar
 
Join Date: Jul 2008
Location: Boston, MA
Posts: 943
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.
Matt_H is offline  
Old 14 August 2020, 00:50   #4
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
@starfox : Adapt, shorten, optimize, etc... it to you needs

malko is offline  
Old 14 August 2020, 09:21   #5
Starfox
Registered User
 
Join Date: Aug 2020
Location: Germany
Posts: 18
Thanks to all this helps me very much
Starfox is offline  
Old 15 August 2020, 16:50   #6
Starfox
Registered User
 
Join Date: Aug 2020
Location: Germany
Posts: 18
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 is offline  
Old 16 August 2020, 14:25   #7
Starfox
Registered User
 
Join Date: Aug 2020
Location: Germany
Posts: 18
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
Starfox is offline  
Old 17 August 2020, 00:46   #8
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Quote:
Originally Posted by StingRay View Post
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

Last edited by malko; 17 August 2020 at 01:08. Reason: typo
malko is offline  
Old 07 October 2021, 14:06   #9
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
Lightbulb 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

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 .

Last edited by malko; 11 October 2021 at 00:26.
malko is offline  
Old 07 October 2021, 14:32   #10
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
Quote:
Originally Posted by malko View Post
[/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.
Thomas Richter is offline  
Old 07 October 2021, 15:50   #11
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
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.
malko is offline  
Old 07 October 2021, 17:24   #12
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,215
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?
Thomas Richter is offline  
Old 07 October 2021, 18:13   #13
malko
Ex nihilo nihil
 
malko's Avatar
 
Join Date: Oct 2017
Location: CH
Posts: 4,856
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}.
malko is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable injection? solarmon support.WinUAE 12 20 January 2019 12:05
AmigaDOS wait for user input Sinphaltimus Coders. Scripting 11 25 February 2018 02:47
WHDload 17.1 problem with user input Fieldday project.WHDLoad 10 27 February 2013 08:54
getting a user to press a key via AmigaDOS DeafDaz Coders. System 3 10 January 2012 17:37
Variable Master Clock wiltshireguyuk request.UAE Wishlist 0 13 December 2004 16:40

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:04.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08640 seconds with 16 queries