I need to ensure that the last character in a string is a /
x="test.com/"
if [[ $x =~ //$/ ]] ; then
x=$x"extention"
else
x=$x"/extention"
fi
at the moment, false always fires.
Join Stack Overflow to learn, share knowledge, and build your career.
|
I need to ensure that the last character in a string is a
at the moment, false always fires. |
|||
|
|
|
Like this, for example:
|
|||||||||
|
|
Your condition was slightly incorrect. When using You'd have got expected results if you said
instead of
|
|||
|
|
|
You can index strings in Bash using
|
|||||
|
|
You can do this generically using bash substrings
Therefore
For future references,
has all the magic
|
||||
|
|