Josh Bond
Josh Bond

Reputation: 1819

Passing sed a shell-script variable which contains spaces

Ignore the .bat extensions, just a habit from the old dos batch file days.

I have 2 simple shell scripts. I want to pass a filename with spaces (some file with spaces.ext) from little.bat to big.bat, as you can see below. It won't let me put the filename in single or double quotes.

First one called little.bat:

./big.bat some file with spaces.ext

Second one called big.bat:

cat template.iss | sed "s/replace123/$1/g" | sed "s/replace456/$1/g" > $1.iss

Upvotes: 0

Views: 4582

Answers (2)

dandrews
dandrews

Reputation: 3045

You can escape each space with a backslash:

some\ file\ with\ spaces.ext

That way, each space is passed on quoted, and the shell won't parse the space to mean "this is the end of one argument and the start of another".

Upvotes: 0

Karoly Horvath
Karoly Horvath

Reputation: 96326

Escape spaces with another sed command.

you can fine details about the idea here: Escape a string for a sed replace pattern

Upvotes: 1

Related Questions