I\'m new to shell scripting but getting this error and cant figure out what up.
sed: 1: \"/Users/local/Do ...\": extra characters at the end of d command
sed: 1
Given that sed
seems to think you're running a delete line
command (d
), you may want to output the command to see what's actually in that environment variable of yours:
for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
echo sed -i "s/HOSTNAME/${PSM_SERVER_ADDRESS}/g" $fl
done
There's a good chance the PSM_SERVER_ADDRESS
is corrupting your sed
command (and may need to be processed to make it clean). One way to do this (provided you have a recent enough sed
) would be to use delimiters that do not appear in the environment variable, for example:
sed -i "s?HOSTNAME?${PSM_SERVER_ADDRESS}?g" $fl
Since you've accepted this answer, I may as well add the resolution for the additional problem you found. It appears that BSD sed
, unlike Linux, has a requirement that you provide an extension to the -i
option. So, while Linux allows:
sed -i "sed-command"
to edit in-place, the BSD variant needs to have:
sed -i "" "sed-command"
with an empty backup suffix.
Without that, sed
may use your command as the extension and your first file name as the command.