*** DISCLAIMER: The information on these pages is not an official instruction or documentation. No responsibility will be taken. Use at your own risk. ***

Saturday, August 12, 2017

how do I properly read user input using a AmigaDOS script?

- user input handling via "ask" isn't sufficient
- empty user input (empty string, user just hit return) can't be checked

Possible solution:

this is an example AmigaDOS script asking user for an ip address, and using a default value if user just hits return:

; default value:
set DEF_IP

; message to user, including default value:
echo "please enter your IP address (default: ${DEF_IP}):"

; unset variable before use, for proper testing afterwards:
unset IP

; read user input into variable.
; if user just hits return, variable doesn't get set.
set >nil: IP ?

; get variable, suppress output:
get >nil: IP

; if there was an error, it means variable hasn't been set.

    ; use default value if there was an error
    set IP ${DEF_IP}

; print result (default value, or user input)
echo "using IP address: ${IP}"

No comments:

Post a Comment

Your comment will published after it has been reviewed.