之前也接触过shell,但是真没怎么用过。
这次因为实习,所以要好好看看shell编程,下面是随便写的shell小脚本。
用来记录一些信息。
#notemessage.sh
#!/bin/bash
while true
do
echo "Phone number?"
read phone
echo "Name?"
echo "Your name is $name"
read name
echo "Age?"
read age
now=`date "+%Y.%m.%d %H:%M:%S"`
echo -e "now:$now\nphone:$phone\nname:$name\nage:$age\n">>data.txt
done
运行:
bash ./notemessage.sh
cat data.txt
为了更好用,比如提供一些筛选的信息,也可以用cut裁剪字符串,不过cut貌似不适合用于以若干空格或换行为依据的裁剪。
可以把上面的输出格式改一下,用cut就好了~