那些年写过的shell------模式匹配

来源:互联网 发布:overcooked for mac 编辑:程序博客网 时间:2024/05/02 00:38
#! /bin/bash
####################################################
##Author:   freeking
##Created:  July 28th 2013
##Description   match the pattern as the parameters
####################################################

varname="root/home/free/Program/ShellProgram"

#match the first '/' from the beginning and return the rest
echo ${varname#*/}

#match the last '/' from the beginning and return the rest
echo ${varname##*/}

#match the first '/' from the end and return the rest
echo ${varname%/*}

#match the last '/' from the end and return the rest
echo ${varname%%/*}

echo ${PATH}
#replace the first ':' with '\n'
echo -e ${PATH/:/'\n'}

#replace the all ':' with '\n'
echo -e ${PATH//:/'\n'