Skip to main content
1 of 3
lonewarrior556
  • 2.2k
  • 5
  • 17
  • 13

how to replace a string in a file and over ride the file?

I wrote my script using the the folder ~/deleted (its a long script) after using ""~/deleted"" for the whole script I want to let the user choose the directory by putting the path in ~/.rm.cfg

my file starts like this

#!/bin/bash

defaultpath=~/deleted

if [ -s ~/.rm.cfg ]
then
    defaultpath=$(head -1 ~/.rm.cfg)
fi

I need to replace every ""~/deleted"" with ""$defaultpath"" in my script. is there a way to do it in command line such that it saves and replaces the original file?

I can't get either perl or sed to work

lonewarrior556
  • 2.2k
  • 5
  • 17
  • 13