Bash parameter expansion magic for “substitute all”

by

The relevant bit is:

for n in *; do mv “$n” ${n// /_}; done

Noting that the double / after the variable name is what tells it to substitute all (rather than first-only).

Advertisements

One Response to “Bash parameter expansion magic for “substitute all””

  1. Ed Says:

    Wow, didn’t know about that pattern substitution syntax. It’s not in “Linux in a Nutshell” though other pattern matching syntaxes are. Very helpful. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: