0
点赞
收藏
分享

微信扫一扫

量化交易之linux篇 - 终端输入超时&隐式输入、分支语句、逐行读取文件


输入超时
#!/bin/bash

if read -t 5 -p "please enter your name: " name
then
echo name is $name
else
echo
echo time is over.
fi

分支语句
#!/bin/bash

read -n1 -p "Do you wanna continue?[Y/N]:" answer

case $answer in
Y|y) echo
echo "yes";;
N|n) echo
echo "no"
exit;;
esac
echo "end..."

隐式输入
#!/bin/bash

read -s -p "enter password: " password
echo password is $password

逐行读取文件
#!/bin/bash

count=1
cat test | while read line
do
echo line $count: $line.
count=$[ $count + 1 ]
done

举报

相关推荐

0 条评论