[NTLUG:Discuss] bash question

Richard Cobbe cobbe at airmail.net
Fri Sep 14 11:54:25 CDT 2001


Lo, on Thursday, September 13, Wrenn, Bobby J. did write:

> So, I'll ask again. 

(Sorry, I get this list in digest form; both your questions just arrived at
once.)

> 
> Will the converse work? If I want to put the spaces back in, would:
> 
>     mv "$file" ${file/-// }
> 
> be the correct expression?

Almost---
    mv "$file" "${file//-/ }"
(...assuming, of course, that you don't have any extraneous hyphens in your
filenames.)  Note the position of the double slash and the quotes.

The double slash goes between the variable name and the pattern to be
replaced; it means `replace all instances' instead of `just replace the
first'.  In your attempt, the replacement string would, I think, be `/ ',
which won't work---the slash will get interpreted as a directory separator,
causing all kinds of error messages.

Check out the `Parameter Expansion' section of the bash manpage for the
full story.

Richard



More information about the Discuss mailing list