6-字符串篇

来源:互联网 发布:redis主从数据库同步 编辑:程序博客网 时间:2024/05/16 16:18

字符串截取

#!/bin/bashhostname="cat.host_name is cat.super.com"string=${hostname:3}echo $stringstring1=${hostname%.*}string2=${hostname%%.*}string3=${hostname#*.*}echo $string1echo $string2echo $string3exit 0

获取长度

#!/bin/bashbook="This is a script's book"size=${#book}size2=$(expr length "$book")echo $sizeecho $size2exit 0

流重定向

#!/bin/bashFROM='from:root@cat.super.com'TO='to:cat@cat.super.com'SUBJECT='subject:shell script'MESSAGE='This is bash shell script'F_NAME='linux_shell'cat > $F_NAME << HERE$FROM$TO$SUBJECT$MESSAGEHEREexit 0
0 0
原创粉丝点击