What does the double slash mean in `${f// /_}`?

Thats a replacement pattern using bash parameter expansion.

In ${f// /_}:

  • The double slashes // are for replacing all occurrences of space with _, if you put one slash /, only first space is going to be replaced

  • The space is there because you are replacing space (with underscore)

So the pattern basically is:

${parameter//find/replace}

Check man bash to get more idea.

To get to the Parameter Expansion section of man bash at once:

LESS=+/'Parameter Expansion' man bash

The section "{f// /_} means replace every space with and underscore. This is using Bash parameter expansion, the variable f defined in the for f in *\ *; will be run through for every match of shell expansion (globbing). Each time the filename found will become the value $f.

The parameter expansion works with the // meaning every occurrence of the character following // (space in this example), should be replaced by the character after / (underscore in this example).

Tags:

Bash