I have a shell script that takes 3 parameters and performs text substitutions based on those parameters. The first parameter is the text to be replaced, the second is the text to replace it with, and the third is the file name. The script works unless the file name has a space. I am not sure how to get sed to parse the filename, and not break it into two files. The current version of the script is as follows:
#! /bin/sh
oldString=$1
newString=$2
file=$3
oldStringFixed=$( echo "$oldString" | sed -e "s/\("\''[]*^+\.$[-]\)/\\\1/g' )
sed -e "s/$oldStringFixed/$newString/g" "$file"> newfile.updated
mv newfile.updated "$file"
When invoked like:
./script replacethis withthis on this.txt
the name on this.txt
is broken into two. Can anyone explain how to deal with files that have spaces in their names?