# Scripting - Asking user for input.

**URL:** <https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678>\
**Category:** Scripting\
**Created:** [August 4, 2014, 3:01pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678 "2014-08-04T15:01:55Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![marrold](https://forum.mikrotik.com/letter_avatar/marrold/32/6_449c533f586939b6e5f246632a46421f.png) [@marrold](https://forum.mikrotik.com/u/marrold)\
**Post date:** [August 4, 2014, 3:01pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/1 "2014-08-04T15:01:55Z")

</div>

Hi all,

I’m making an ‘install script’ to install another script on routerboards. Currently it’s setup as a function, and the user can pass arguments to the function.

Is there any way for a script to ask for user input via the console? E.G

$Please enter WAN interface-  
$\_

---

<div class="post-metadata">

**Author:** ![boen\_robot](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/boen_robot/32/241_2.png) [@boen\_robot](https://forum.mikrotik.com/u/boen_robot)\
**Post date:** [August 4, 2014, 3:05pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/2 "2014-08-04T15:05:55Z")

</div>

There’s the “/terminal inkey” command, which asks the user for a single key, and returns the key code of the pressed key, which you can then decode into an ASCII character or a keyboard key.

It’s as cumbersome to work with as it sounds… You need to invoke it as many times as the number of characters you need, or more precisely, keep invoking it until a new line is entered (character code 13). Oh, and you better support backspace (character code 8 ) too. If you manage to elegantly abstract away such stuff, you may as well create a function for that… One which wouldn’t need prompts upon _its_ install 😉 . But at that point, I think we can agree that’s overkill.

---

<div class="post-metadata">

**Author:** ![marrold](https://forum.mikrotik.com/letter_avatar/marrold/32/6_449c533f586939b6e5f246632a46421f.png) [@marrold](https://forum.mikrotik.com/u/marrold)\
**Post date:** [August 4, 2014, 3:19pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/3 "2014-08-04T15:19:40Z")

</div>

boen\_robot, this is the second time you’ve assisted with my scripting this week.

Thanks, it’s much appreciated.

---

<div class="post-metadata">

**Author:** ![A9691](https://forum.mikrotik.com/letter_avatar/a9691/32/6_449c533f586939b6e5f246632a46421f.png) [@A9691](https://forum.mikrotik.com/u/A9691)\
**Post date:** [March 1, 2018, 8:19pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/4 "2018-03-01T20:19:19Z")

</div>

Try out the following:

```plaintext
# function to prompt user to enter a value
:global read do={:return}

# storing the value entered by the user
:local userinput [$read]

```

It is interesting, that if the user enters 192.168.10.0/24, [:typeof $userinput] will be ip-prefix, not str.

---

<div class="post-metadata">

**Author:** ![sebastia](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/sebastia/32/811_2.png) [@sebastia](https://forum.mikrotik.com/u/sebastia)\
**Post date:** [March 1, 2018, 9:09pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/5 "2018-03-01T21:09:28Z")

</div>

You may want to have a look at this ones too:  
[http://forum.mikrotik.com/t/how-to-handle-y-n-response-in-rsc-script/37083/1](http://forum.mikrotik.com/t/how-to-handle-y-n-response-in-rsc-script/37083/1)  
and  
[http://forum.mikrotik.com/t/functions-in-cmd-scripts/34902/1](http://forum.mikrotik.com/t/functions-in-cmd-scripts/34902/1)

---

<div class="post-metadata">

**Author:** ![DiVersant](https://forum.mikrotik.com/letter_avatar/diversant/32/6_449c533f586939b6e5f246632a46421f.png) [@DiVersant](https://forum.mikrotik.com/u/DiVersant)\
**Post date:** [June 4, 2018, 8:21am UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/6 "2018-06-04T08:21:07Z")

</div>

I’m trying to make a initial configuration script and need to parse user input to set router name, WAN ip and GW, local ip and GW and so on…  
When I’m trying to use

```plaintext
# function to prompt user to enter a value
:global read do={:return}

# storing the value entered by the user
:local userinput [$read]

```

put $read  
showing me “;(eval (eval /return))” as answer ☹  
What I’m doing wrong?  
FW from 6.39 up to 6.42.3.

---

<div class="post-metadata">

**Author:** ![cantanko](https://forum.mikrotik.com/letter_avatar/cantanko/32/6_449c533f586939b6e5f246632a46421f.png) [@cantanko](https://forum.mikrotik.com/u/cantanko)\
**Post date:** [June 20, 2018, 1:40pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/7 "2018-06-20T13:40:42Z")

</div>

You need to :put $userinput, not :put $read 🙂

---

<div class="post-metadata">

**Author:** ![dasiu](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/dasiu/32/567_2.png) [@dasiu](https://forum.mikrotik.com/u/dasiu)\
**Post date:** [June 20, 2018, 2:39pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/8 "2018-06-20T14:39:11Z")

</div>

Or use:  
:put [$read] - to run the script (as for user input) and immediately put it on the screen without “storing it” in a variable 🙂.

---

<div class="post-metadata">

**Author:** ![dke](https://forum.mikrotik.com/letter_avatar/dke/32/6_449c533f586939b6e5f246632a46421f.png) [@dke](https://forum.mikrotik.com/u/dke)\
**Post date:** [June 4, 2020, 4:55am UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/9 "2020-06-04T04:55:49Z")

</div>

> [@mada3k](#):
>
> You need to :put $userinput, not :put $read 🙂

```plaintext
:put $userinput

```

is also empty for me after asked for a value (v6.47).

---

<div class="post-metadata">

**Author:** ![msatter](https://forum.mikrotik.com/letter_avatar/msatter/32/6_449c533f586939b6e5f246632a46421f.png) [@msatter](https://forum.mikrotik.com/u/msatter)\
**Post date:** [November 23, 2020, 1:35pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/10 "2020-11-23T13:35:21Z")

</div>

> [@](#):
>
> > [@mada3k](#):
> >
> > You need to :put $userinput, not :put $read 🙂
> 
> ```plaintext
> :put $userinput
> 
> ```
> 
> is also empty for me after asked for a value (v6.47).

If you get actual code then use an extra pair square brackets.

```plaintext
:local userinput [$read]; :put [$userinput];

```

or use :set, instead of local/global

```plaintext
:set [userinput [$read]]; :put $userinput

```

---

<div class="post-metadata">

**Author:** ![liuyao](https://forum.mikrotik.com/letter_avatar/liuyao/32/6_449c533f586939b6e5f246632a46421f.png) [@liuyao](https://forum.mikrotik.com/u/liuyao)\
**Post date:** [November 18, 2021, 4:13pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/11 "2021-11-18T16:13:44Z")

</div>

{:local userinput [:return]; :put [$userinput]; } nice

---

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [November 18, 2021, 6:02pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/12 "2021-11-18T18:02:57Z")

</div>

This do not work, the second put is not executed, the terminal print the result regardless the :put

---

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [November 18, 2021, 6:10pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/13 "2021-11-18T18:10:40Z")

</div>

This is a 6.47.10 working example: (not tested on other versions)

```plaintext
{
:local readinput do={:return}
:put "\r\nInsert a string you want use as"
:local input [$readinput]
:put "\r\nYou have insert: $input"
:put "Which is a $[:typeof $input]\r\n"
}

```

---

<div class="post-metadata">

**Author:** ![Jotne](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/jotne/32/56097_2.png) [@Jotne](https://forum.mikrotik.com/u/Jotne)\
**Post date:** [November 18, 2021, 6:58pm UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/14 "2021-11-18T18:58:34Z")

</div>

Works on 6.48.4 as well.

---

<div class="post-metadata">

**Author:** ![liuyao](https://forum.mikrotik.com/letter_avatar/liuyao/32/6_449c533f586939b6e5f246632a46421f.png) [@liuyao](https://forum.mikrotik.com/u/liuyao)\
**Post date:** [November 19, 2021, 10:27am UTC](https://forum.mikrotik.com/t/scripting-asking-user-for-input/79678/15 "2021-11-19T10:27:10Z")

</div>

> [@](#):
>
> This is a 6.47.10 working example: (not tested on other versions)
> 
> ```plaintext
> {
> :local readinput do={:return}
> :put "\r\nInsert a string you want use as"
> :local input [$readinput]
> :put "\r\nYou have insert: $input"
> :put "Which is a $[:typeof $input]\r\n"
> }
> 
> ```

You are right. Thank you
