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?
Example:
sudo add-apt-repository ppa:"this"/"and_that" 1 2 Answers
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.
2You 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 1