Using variable with the sed command

8

I have the following occurrence:

DirUpload=/var/log
find $DirUpload | sed 's/$DirUpload//g'

The question is, how to use variable along with sed?

    
asked by anonymous 11.10.2016 / 20:40

2 answers

6

According to the response from SOen : / p>

DirUpload=/var/log
find $DirUpload | sed "s|$DirUpload\/||g"
  • Use double quotes to expand the variables
  • Use a separator other than / (in the example: | )
11.10.2016 / 21:03
3

Just use double quotes rather than simple quotes:

  DirUpload=/var/log
  find $DirUpload | sed "s/$DirUpload//g"
    
11.10.2016 / 20:48