這是我想要的XML文件進行編輯如何創建Android的shell腳本中的XML編輯字符串
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="public_checkins" value="false" />
<string name="checkins">[{"storeName":"Rundle Street","prize":"price_fwh","checkinTime":1352717951195,"prizeClaimed":false,"storeId":57,"expired":false},{"storeName":" Street","prize":"price_fmf","checkinTime":1352717723886,"prizeClaimed":false,"storeId":57,"expired":false}]</string>
*<string name="uuid">30212345-0c1e-dcb-974e-5effa7f016be</string>*
</map>
我試圖創建一個shell腳本編輯字符串UUID和替換每次我運行腳本時,都會隨機生成一個數字序列。
下面是我想出的腳本。
#!/system/bin/sh
set number=$RANDOM
echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="public_checkins" value="false" />
<string name="checkins">[{"storeName":" Street","prize":"price_fwh","checkinTime":1352717951195,"prizeClaimed":false,"storeId":57,"expired":false},{"storeName":"Rundle Street","prize":"price_fmf","checkinTime":1352717723886,"prizeClaimed":false,"storeId":57,"expired":false}]</string>
<string name="uuid">302$number-0c1e-dcb-974e-5effa7f016be</string>
</map>
" > /data/data/com.app/shared_prefs/app.xml
字符串資源只讀您無法對其進行編輯的Perl會更合適。您正在將字符串文件應用於app.xml。是嗎?如果是這樣,那麼你想完成什麼。相反,您可以使用StringFormat方法爲字符串資源中定義的格式生成字符串。 – Dharmendra
我想將隨機數回顯到app.xml中存在的字符串中。 – Lam