Skip to content

Latest commit

 

History

History
30 lines (28 loc) · 629 Bytes

30.md

File metadata and controls

30 lines (28 loc) · 629 Bytes

题目要求

写一个脚本,执行后,打印一行提示“Please input a number:",要求用户输入数值,然后打印出该数值,然后再次要求用户输入数值。直到用户输入"end"停止。

参考答案

#!/bin/bash
while :
do
    read -p "Please input a number: " n
    if [ -z "$n" ]
    then
	echo "请输入一个纯数字."
	continue
    fi
    if echo $n |grep -qi 'end'
    then
	exit
    fi
    n1=`echo $n|sed 's/[0-9]//g'`
    if [ -n "$n1" ]
    then
	echo "请输入一个纯数字."
        continue
    else
	echo "你输入的数字是: $n"
        continue
    fi
done