Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create an interactive bash script where I can collect user input variables to be used as arguments in another command. Can someone provide me an example of this?

Currently i want to do:

  1. what type of content you want to delete?
  2. what is the status?

then feed it into a mysql delete query command.

share|improve this question
Are you referring to the command line arguments or input from the user when the script is running? – David Kohen Mar 23 '13 at 18:01

You can use read or select:

read -p prompt answer; echo "$answer"
read -p 'Continue (y/n)? ' -n1 answer; echo; [[ $answer = [yY] ]] || return

PS3='What is the capital of Sweden (1-3)? '; select answer in Gothenburg Stockholm Uppsala; do [[ $answer = Stockholm ]] && { echo Correct; break; } || echo Try again; done

share|improve this answer

With the command 'read' you can collect information from input and store it in a variable/file that you can subsequently pass through to your other script.

With the -s option it even masks the user input while typing: great for inputting for example passwords.

share|improve this answer

For such a job, perhaps a fuller language like Python is a better match. You can call programs from it, or do your dubious deeds directly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.