开发者社区> 问答> 正文

如何让 Shell 就脚本得到来自终端的输入?

如何让 Shell 就脚本得到来自终端的输入?

展开
收起
黄一刀 2020-03-06 23:35:38 1074 0
1 条回答
写回答
取消 提交回答
  • read 命令可以读取来自终端(使用键盘)的数据。read 命令得到用户的输入并置于你给出的变量中。例子如下:

    vi /tmp/test.sh

    #!/bin/bash echo ‘Please enter your name’ read name echo “My Name is $name”

    ./test.sh

    Please enter your name ThinkWon My Name is ThinkWon

    2020-03-06 23:36:02
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Shell 脚本速查手册 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载