regex - bash: String Operator with regular expression -
I want to list all the files in my home
folder, and # < / Code> in the file name. For example:
# emacs #
to .emacs
This is my code
< Code> should be printed as $ {ls ~} in dir # trim trailing trailing filename = "$ {dir # \ #}" echo $ {filename} done
but it Even though #
was still managing the regular expression $ {dir # \ #}
in the terminal
Can you tell me that my code Where's the smell?
Remove #
should be the filename,
filename = "$ {dir //}"
filename = "$ {dir // \ # /}"
The rest are fine for both Saigwin and Solaris.
If you need to delete all content before # then
filename = "$ {dir ## * #}"
If you need to remove all content after the #
filename = "$ {dir %% # *}"
, here The full explanation is that I am copying and pasting bash substring replacement
$ {string / substring / replacement} and $ substring $ substation with $ substring first match Replace. $ {String // Substring / Replacement} $ $ String% substring matches $ substring $ match with at least $ substring from the back of the string. $ {String %% substring} $ {String # substring} deletes the longest match of the $ substring behind the $ string, removes at least the match of the $ substring against the $ string. $ {String ## substring} $ removes longest match of substring from front of string.
Comments
Post a Comment