【shell脚本学习-2】

本文深入探讨了Bash脚本的基础语法与高级用法,包括读取输入、条件判断、循环控制等,并详细解析了Linux下常用命令如grep、sed、find等的使用技巧,特别关注正则表达式的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/bin/bash - #echo do you have exetuate this project \n printf "please input your passwd" stty -echo read pass < /dev/tty printf "please agein input your passwd" read pass2 < /dev/tty stty echo #tr -s > 1.txt | sort > 2.txt #echo "1 6 8 1 4 9" > 1.txt | sort 1.txt | tail 1.txt #cat /dev/null #!/bin/bash #cat /bin/liupeng | grep a | wc #$1 #read $x #echo $x #set -x #跟踪 #echo firset echo #set +x #取消跟踪 #echo second echo #locale -a | grep "^L" #环境变量 #LC_ALL=da locale ck LC_TIME ######------------------------------grep+正则表达式-----------------------------# #who | grep -F u1 #判断登录用户 #cat 1.txt | grep ^a | grep b$ #cat 1.txt | grep Aa.Aa #[Aa]d #含有Aa的字符 #cat 1.txt | grep ^Aa #以Aa开头的字符 #cat 1.txt | grep Aa$ #以Aa结尾的字符 #cat 1.txt | grep [[:digit:]] | grep ^2 #匹配含有数字的行列 #cat 1.txt | grep [[:alnum:]] #cat 1.txt | grep \digit #cat 1.txt | grep ab*c #匹配含有一个a额字符 #cat 1.txt | grep [[:upper:]]\{3\}$ #匹配后三位为大写的字符 #cat 1.txt | grep ab?c #匹配ab和abc #cat 1.txt | grep ab+c #----------------------------------sed+正则表达式_______________________________ #sed 's/:.*//' /root/1.txt #find /root -type d -print #mkdir -p /home/1 #sed 's;/home/1;/home/2;' # cat /root/1.txt | sed 's/a/B/g' #替换字符 #n #printf "hello world" #sed -n '/c/p' *.txt #sed -n '$p' "$1" #sed -n '2,5p' /root/1.txt #匹配打印的行数 echo "hello world" | sed 's/world/shell/' #替换指定的字符

转载于:https://www.cnblogs.com/activecode/p/9526393.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值