美文网首页
Bash超级会 - 4.用户输入

Bash超级会 - 4.用户输入

作者: etfolin | 来源:发表于2020-12-21 23:05 被阅读0次

获取用户输入是 交互( interactive )中至关重要的部分。

read

read 变量

#!/bin/bash
echo "Enter Your Age"
read age
echo "Your age is $age"

但在命令行中,通过参数获取用户输入才是更正宗的做法。

#!/bin/bash
echo "Total arguments : $#"
echo "Username: $1"
echo "Age: $2"
echo "Full Name: $3"

#将此文件保存为:arguments.sh
bash arguments.sh tuts 30 'Foss Linux'

相关文章

网友评论

      本文标题:Bash超级会 - 4.用户输入

      本文链接:https://www.haomeiwen.com/subject/alvhnktx.html