2016-04-02 110 views
0

所以我最近做了一個簡單的bash腳本,我想與其他人分享。所以我嘗試讓腳本搜索文件夾中的其他人將它們放置在其中的文件,這對於一些文件來說工作得很好。替換不是變量的bash腳本中的文本

儘管我在腳本中有一個不接受變量的命令,但它們會被傳遞,但它們不會在命令中被替換。因此,不必使用變量,我必須使用文件的路徑,這些文件僅在我的計算機上。

因爲我希望每個人都使用該腳本,我需要一種方法來替換這些路徑。所以我想到了這一點:

使用相同的命令,找到另一個文件來找到這個。然後使用該命令找到的路徑替換腳本中文件的路徑。

雖然我的問題是,我沒有找到我想要的東西。這裏是我的代碼:

#!/bin/bash 

#variables that store the paths 

dtree=$(find Downgrade -type f -iname DeviceTree*) 
ramdisk=$(find Downgrade -type f -iname *.dmg) 
kernel=$(find Downgrade -type f -iname kernelcache*) 

#the execution of the command. (Using normal EOF without 」」 doesn’t replace the strings.) 

./irecovery -s <<"EOF" >/dev/null 

/send Downgrade/DeviceTree.n90ap.img3 #This needs to be replaced by $dtree 
devicetree 
/send Downgrade/048-2441-007.dmg #This needs to be replaced by $ramdisk 
ramdisk 
/send Downgrade/kernelcache.release.n90 #This needs to be replaced by $kernel 
bootx 
/exit 
EOF 

回答

0

雖然我不知道你的問題,你可以通過嘗試更換串sed

sed "s/old/new/g"