Celeb Glow
general | March 23, 2026

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.

2

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
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy