Shell编程常用语句

1. 批量生成数字

# Generate phone number
base_num=16600000000
for ((i=0;i<100000;i++))
do
echo $(($base_num+$i)) >> phone_num.txt
done

2. 链接数据库查询

# SQL语句执行结果保存在文件中
sqlplus $username/$password@$dbname <<EOF >/dev/null
spool filename
select * from table where a=b;
spool off
EOF

# 查询结果赋值
results=$(sqplus -s $username/$password@$dbname <<EOF
set pagesize 0;
select name from table where a=b;
EOF
)

3. 循环等待输入

while true; do
    echo -n "Continue?[y|n] "
    read -r input
    if [ "${input}" = 'y' ]; then
        break
    elif [ "${input}" = 'n' ]; then
        exit 0
    else
        echo "Wrong Input, please input again"
        continue
    fi
done
posted @ 2022-11-16 22:59  rustling  阅读(25)  评论(0编辑  收藏  举报