longSir

流水不争先,争的是滔滔不绝

导航

Shell 字符串的相关操作

#!/bin/bash
 
msg="home/desktop/shell/file.txt"

echo "The original string = $msg"
echo "The Length of String = ${#msg}"
echo "The Substring Starting from position 3 = ${msg:3}"
echo "The Substring Starting from position 3 with length of 10 = ${msg:3:10}"
echo "Delete the substring before the first / = ${msg#*/}"
echo "Delete the substring after the last / = ${msg%/*}"
echo "Delete the substring after the first / = ${msg##*/}"
echo "Delete the substring before the last / = ${msg%%/*}"

echo "Replace a first / to . = ${msg/'/'/.}"
echo "Replace all / to . = ${msg//'/'/.}"
:<<EOF
${var}
${#var}
${var:3:2}
${var:0-1:3}
${var:#*'}
${var:##*'}
${var:%*'}
${var:%%*'}
EOF

 

posted on 2022-11-28 15:43  tablong  阅读(6)  评论(0)    收藏  举报