Skip to main content
Solved

Delete and replace an xml file in a directory folder


Forum|alt.badge.img+3

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!

Best answer by mm2270

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 original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • May 3, 2019

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.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • May 3, 2019

@mm2270 Ok thanks I'll try this.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 5 replies
  • May 3, 2019

This worked! Thank you!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings