0

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?

4

1 に答える 1

0

bash の引用規則 (Mac のシェルですよね?) は cmd.exe (Windows シェル) とは異なります。特に、cmd.exe は'通常の文字として扱われますが、bash では引用文字であるため、そうではありません。プログラムに渡されません。'したがって、bash では、 s も引用符で囲む必要があります。

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'

2 番目の修正は、.bash を使用した場合に bash が変数展開を行うのを防ぐため、より安全です$が、最初の修正には、Windows でも機能するという利点があります。

于 2012-11-03T08:51:55.360 に答える