I need to be able to do is replace a space () with a dot (
.
) in a string in bash.
I think this would be pretty simple, but I'm new so I can't figure out how to modify a similar example for this use.
I need to be able to do is replace a space () with a dot (
.
) in a string in bash.
I think this would be pretty simple, but I'm new so I can't figure out how to modify a similar example for this use.
Try this
In bash, you can do pattern replacement in a string with the
${VARIABLE//PATTERN/REPLACEMENT}
construct. Use just/
and not//
to replace only the first occurrence. The pattern is a wildcard pattern, like file globs.You could use
tr
, like this:Example:
From
man tr
:Try this for paths:
It replaces the space inside the double-quoted string with a
+
sing, then replaces the+
sign with a backslash, then removes/replaces the double-quotes.I had to use this to replace the spaces in one of my paths in Cygwin.
Use inline shell string replacement. Example:
See http://tldp.org/LDP/abs/html/string-manipulation.html for more details.
Use parameter substitution: