sed command not working with newline/space define in variable.
Issue
- Refer below steps to reproduce issue
[root@testing]# SRC="tr '\n' ' ' "
[root@testing]# DST="tr -d '\n' "
[root@testing]#
[root@testing]# echo $SRC; echo $DST
tr '\n' ' '
tr -d '\n'
[root@testing]#
[root@testing]# more newfile
testuser LOGFILE=`egrep '^log_file' $UPT_CONF | tr -s ' ' | tr '\n' ' ' | cut -d'=' -f 2 2>/dev/null`
[root@testing]# sed -i "s/$SRC/$DST/g" newfile
[root@testing]#
[root@testing]# more newfile
testuser LOGFILE=`egrep '^log_file' $UPT_CONF | tr -s ' ' | tr '\n' ' ' | cut -d'=' -f 2 2>/dev/null` <============ No change on "tr '\n' ' ' "
[root@testing]#
Environment
- Red Hat Enterprise Linux All
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.