2016-04-02 96 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"