#!/bin/bash function convert(){ keyword=${1//\\/\\\\\\\\} keyword=${keyword//\./\\.} keyword=${keyword//\*/\\\\*} keyword=${keyword//\&/\\\\&} keyword=${keyword//\$/\\\\$} keyword=${keyword//\+/\\\\+} keyword=${keyword//\=/\\\\=} keyword=${keyword//\^/\\\\^} keyword=${keyword//\%/\\\\%} keyword=${keyword//\!/\\\\!} keyword=${keyword//\@/\\\\@} keyword=${keyword//\#/\\\\#} keyword=${keyword//\[/\\\\[} keyword=${keyword//\]/\\\\]} keyword=${keyword//\-/\\\\-} keyword=${keyword//\ /\\ } # keyword=${keyword//\?/\\\\?} ?号不能转义.要不然替换不成功 keyword=${keyword//\"/\\\"} echo $keyword } #调用函数,如果传参有空格,必须加双引号,否则函数会认为是多个参数 repkey=$(convert "$2") repkey1=$(convert "$2") newkey=$(convert "$3") #调用shell脚本sh xxx.sh /root "rep1" "rep2" "hh" 0
原文地址:https://www.cnblogs.com/bretzhao/p/11831208.html
时间: 2024-11-13 10:54:14