When I use the "tab" key in bash
(when you have started to type the filename and you want it to complete), bash
escapes the filename correctly, and if I use exactly that "escaped" filename, it works.
For Instance:
An-Beat - Mentally Insine (Original Mix).mp3
=> After bash
Escapes It Using "TAB" An-Beat\ -\ Mentally\ Insine\ \(Original\ Mix\).mp3
I'm search for a function for bash
that will escape a filename the same way "tab" escapes filenames.
Bash escape character is defined by non-quoted backslash (\). It preserves the literal value of the character followed by this symbol. Normally, $ symbol is used in bash to represent any defined variable.
The escape (\) preceding a character tells the shell to interpret that character literally. With certain commands and utilities, such as echo and sed, escaping a character may have the opposite effect - it can toggle on a special meaning for that character.
About Escaping File PathsCharacters to be escaped include the backslash (\, because it is the escaping character) and the double quotes (").
Use printf
(1):
x='a real \good %* load of c$rap' x=$(printf '%q' "$x") echo $x
will return
a\ real\ \\good\ %\*\ load\ of\ c\$rap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With