Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.