Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex bash脚本中的隐藏字符串_Regex_Bash_Sed_Glob_Tr - Fatal编程技术网

Regex bash脚本中的隐藏字符串

Regex bash脚本中的隐藏字符串,regex,bash,sed,glob,tr,Regex,Bash,Sed,Glob,Tr,我正在努力做到以下几点: obscure ( ) { local txt="$1" echo "$txt" | tr '[:alnum:]' '*' } 因此,如果我这样做: obscure 'mysecretstring' 我得到: ************** 对于tr,我可以使用什么匹配器来代替[:alnum:][/code>来表示“任意字符” 是否有更好的方法来实现模糊?想到的另一个选项是sed 您可以使用纯BASH: obscure() { local tx

我正在努力做到以下几点:

obscure ( ) {
    local txt="$1"
    echo "$txt" | tr '[:alnum:]' '*'
}
因此,如果我这样做:

obscure 'mysecretstring'
我得到:

**************
对于
tr
,我可以使用什么匹配器来代替
[:alnum:][/code>来表示“任意字符”

是否有更好的方法来实现
模糊
?想到的另一个选项是
sed

您可以使用纯BASH:

obscure() {
   local txt="$1"
   echo "${txt//?/*}"
}
“${txt//?/*}”
将用
*
替换
$txt
中的每个字符

测试它:

obscure 'mysecretstring3123213213'
************************

obscure mysecretstring
**************

obscure '!@#$%^&*()_+=-'
**************

obscure '中文版'
***
您可以使用纯BASH:

obscure() {
   local txt="$1"
   echo "${txt//?/*}"
}
“${txt//?/*}”
将用
*
替换
$txt
中的每个字符

测试它:

obscure 'mysecretstring3123213213'
************************

obscure mysecretstring
**************

obscure '!@#$%^&*()_+=-'
**************

obscure '中文版'
***

工作起来很有魅力。谢谢您甚至不需要局部变量:
echo“${1//?/*}”
也可以工作。是的,这是真的,不需要局部变量。即使对于
tr
来说,也不需要它。它就像一个符咒。谢谢您甚至不需要局部变量:
echo“${1//?/*}”
也可以工作。是的,这是真的,不需要局部变量。即使对于
tr
,也不需要它。如果要表示任何可打印字符,可以使用
[:print://code>。如果要表示任何可打印字符,可以使用
[:print://code>。