Results 1 to 3 of 3
Code:
#!/bin/sh
echo Enter directory to replace example [/etc/hosts/]:
read dir
echo Enter original text:
read orginal
echo Enter replaced text:
read replace
if [ "$orginal" = "$replace" ]; then
...
- 06-13-2010 #1
Replace no work
Where is the problem ?Code:#!/bin/sh echo Enter directory to replace example [/etc/hosts/]: read dir echo Enter original text: read orginal echo Enter replaced text: read replace if [ "$orginal" = "$replace" ]; then clear echo Error else find ${dir} -type f -exec sed -i 's/${orginal}/${replace}/g' {} \; fi
- 06-13-2010 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Replace the single quotes with double quotes:
"s/${orginal}/${replace}/g"
- 06-13-2010 #3
Two points:
1) You do realise, that this script is dangerous?
If ${dir} would be empty or "/" for whatever reason, then you have a good chance of corrupting files.
2) It doesnt add value.
2a) If it is intended for a non-technical user, then it lacks input validation and sanitation.
A lot input validation/sanitation
2b) For a technical user it is useless, as it adds no logic. (S)he would be better off calling find/sed directlyYou must always face the curtain with a bow.


Reply With Quote