Mil*_*uzz 5 regex bash shell command-line
我需要确保字符串中的最后一个字符是a /
x="test.com/"
if [[ $x =~ //$/ ]] ; then
x=$x"extention"
else
x=$x"/extention"
fi
Run Code Online (Sandbox Code Playgroud)
此刻,虚假总是火上浇油.
像这样,例如:
$ x="test.com/"
$ [[ "$x" == */ ]] && echo "yes"
yes
$ x="test.com"
$ [[ "$x" == */ ]] && echo "yes"
$
$ x="test.c/om"
$ [[ "$x" == */ ]] && echo "yes"
$
$ x="test.c/om/"
$ [[ "$x" == */ ]] && echo "yes"
yes
$ x="test.c//om/"
$ [[ "$x" == */ ]] && echo "yes"
yes
Run Code Online (Sandbox Code Playgroud)