Ubuntu: Shell script with user input prompt


Is it possible to write a script where the initial command requires user input so that it prompts the user to enter that input before running?


sudo add-apt-repository ppa:"this"/"and_that"  


You can read user input in bash the following way:

read -p "Input this: " this  read -p "Input that: " that  sudo add-apt-repository ppa:${this}/${that}  

read command creates a variable with its value taken from standard input.

In real life scenario you should also sanitize user input (i.e. check for non-alphanumeric characters before calling the command), but you can skip it if it's just for you.


You can use command read to read user input into variables.

#!/bin/bash    echo Enter this:  read this    echo and that:  read and_that    sudo add-apt-repository ppa:$this/$and_that  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »