在编写shell脚本中,经常要处理一些输入参数,在使用过程中发现getopts更加方便,能够很好的处理用户输入的参数和参数值. getopts用于处理用户输入参数,举例说明使用方法: while getopts :a:b:cdefg opt; do case $opts in a) do sth; ...... cde) do another; esac done 几个重要变量: OPTIND:getopts使用OPTIND作为索引,…
一.获取用户输入1.基本读取read命令接收标准输入的输入,或其它文件描述符的输入.得到输入后,read命令将数据输入放入一个标准变量中.[root@rac2 ~]# cat t8.sh #!/bin/bash#testing the read commandecho -n "enter your name:" ---:-n用于允许用户在字符串后面立即输入数据,而不是在下一行输入.read nameecho "hello $name ,welcome to my progra…
python查找指定字符 #!/usr/bin/env python import sys import re f = open("log.txt", "rb") info = open("info.txt", "ab") for line in f.readlines(): if re.search(sys.argv[1], line): info.write(line) info.close() f.close() 当形参…