填写空白Shell脚本

时间:2011-07-22 17:50:50

标签: bash shell

如何编写一个shell脚本来询问问题,然后将答案存储在变量中?我在OS X中使用bash 基本上,这就是我想要做的事情:

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

2 个答案:

答案 0 :(得分:3)

查看read

未经测试的代码:

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

答案 1 :(得分:2)

怎么样......

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