Delete and replace an xml file in a directory folder

skhublall
New Contributor II

Hi Everyone, Newbie Here
I'm trying to replace an existing config xml file in the applications folder.

I packaged the the new config file to add in the existing folder. I wrote a simple script to run before running the package to remove the existing xml file, but for some reason the exisiting file is not being removed

#!/bin/sh

cd /Applications/Adobe InCopy CC 2015/Plug-Ins/vjoon K4

rm -rf 'K4 Config.xml'

Am I doing this wrong? Thanks in advance!

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

What's wrong is the spaces in the path that you're trying to cd into aren't escaped. In the shell, spaces usually have to be escaped, or, the path has to be enclosed in double quote marks.

But taking a step back, you don't need to cd into the directory first. You can just specify the full path to the xml you want to delete and use that in the rm command, like this

rm -rf "/Applications/Adobe InCopy CC 2015/Plug-Ins/vjoon K4/K4 Config.xml"

As long as you confirm the path is correct, that should be all you need in your script. Though you could drop a 2>/dev/null at the end of that line, just in case the XML happens to not be present, so the script won't exit with an error.

View solution in original post

3 REPLIES 3

mm2270
Legendary Contributor III

What's wrong is the spaces in the path that you're trying to cd into aren't escaped. In the shell, spaces usually have to be escaped, or, the path has to be enclosed in double quote marks.

But taking a step back, you don't need to cd into the directory first. You can just specify the full path to the xml you want to delete and use that in the rm command, like this

rm -rf "/Applications/Adobe InCopy CC 2015/Plug-Ins/vjoon K4/K4 Config.xml"

As long as you confirm the path is correct, that should be all you need in your script. Though you could drop a 2>/dev/null at the end of that line, just in case the XML happens to not be present, so the script won't exit with an error.

skhublall
New Contributor II

@mm2270 Ok thanks I'll try this.

skhublall
New Contributor II

This worked! Thank you!