Prompt user from bash command substitution

前端 未结 1 1093
眼角桃花
眼角桃花 2021-01-29 08:46

I am looking for a one-liner to prompt user for multiple inputs and execute a command using the user inputs as arguments.

The naive approach is:

read -p          


        
相关标签:
1条回答
  • 2021-01-29 09:27

    Sounds like a homework question to get you to look at functions. If you had a function like:

    input() { read -p "$1:" user_input; echo "$user_input"; }
    

    Then your line:

    the_command some_complicated_arguments "$(input shirt_size)" "$(input age)"
    

    Would prompt and print the complete line. Although this does nothing to check for valid input or no input.

    0 讨论(0)
提交回复
热议问题