1

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.

  • Are you referring to the command line arguments or input from the user when the script is running? – Didi Kohen Mar 23 '13 at 18:01
2

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

0

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.

0

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.

Your Answer

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

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