Question

I created a batch file for windows that executes some xmlstarlet commands. I want to write it as .sh file so that i can run it on mac. The problem is.. Some commands are working fine in windows but not in mac. It didn't show any error too. Eg.

**xml ed -L -d //intent-filter//category[@android:name='android.intent.category.LAUNCHER'] my_folder\AndroidManifest.xml**

In windows, above command deletes the mentioned xml tag. BUt it does nothing in mac. But the command

**xml sel -t -m //manifest -v //manifest/@package mim_apk_proj\AndroidManifest.xml**

is working fine in both mac and windows. I have installed xml tool. Checked /usr/local/bin. It has libxslt.dylib and libxml2.dylib. I dont know where the problem lies? Can someone help?

Was it helpful?

Solution

The quoting rules for bash (that's the shell on your mac, right?) are different from cmd.exe (the Windows shell), in particular, cmd.exe treats ' as a normal character while to bash it is a quoting character so it isn't passed to the program. In bash you therefore need to quote the 's as well:

xml ed -L -d //intent-filter//category[@android:name='android.intent.category.LAUNCHER'] my_folder\AndroidManifest.xml
# becomes
xml ed -L -d "//intent-filter//category[@android:name='android.intent.category.LAUNCHER'] my_folder\AndroidManifest.xml"
# or, since XPath treats both kinds of quotes identically you can also use
xml ed -L -d '//intent-filter//category[@android:name="android.intent.category.LAUNCHER"] my_folder\AndroidManifest.xml'

The second fix is safer because it also prevents bash from doing any variable expansion if you use $, but the first fix has the advantage of working in Windows as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top