简体   繁体   English

填空 Shell 脚本

[英]Fill-in-the-Blank Shell Script

How do I write a shell script that will ask a question and then store the answer in a variable?如何编写 shell 脚本来提出问题,然后将答案存储在变量中? I am using bash in OS X.我在 OS X 中使用 bash。
Basically, this is what I want to do:基本上,这就是我想要做的:

What is your name? (prompt for a name)
You entered: (and the name that the user entered)

Look into read .看看read

Untested code:未经测试的代码:

echo "What is your name?"
read name
echo "You entered: $name"

How about...怎么样...

#!/bin/bash
/bin/echo -n "What is your name? "
read name
/bin/echo "You said $name"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM