linux运维经验分享
2017年11月5日
shell习题
No Comments
aming
写一个脚本让用户输入多个城市的名字(可以是中文),要求不少于5个,然后把这些城市存到一个数组里,最后用for循环把它们打印出来。
参考答案:
#!/bin/bash read -p "请输入至少5个城市的名字,用空格分隔:" city n=`echo $city|awk '{print NF}'` if [ $n -lt 5 ] then echo "输入的城市个数至少为5" exit fi name=($city) for i in ${name[@]} do echo $i done
shell习题-数组
2017年11月5日
shell习题
No Comments
aming
写一个脚本让用户输入多个城市的名字(可以是中文),要求不少于5个,然后把这些城市存到一个数组里,最后用for循环把它们打印出来。
参考答案: