sed: \ in variable dissappears in append feature
I want to append below find command in a file under a line matching a string.
command: Quote:
Quote:
Quote:
Quote:
Quote:
|
Yes, the sed command will interpret the backslash itself, and the sequences "\(" and "\)" are just "(" and ")" respectively. If you want the sed command to treat the backslashes literally, you would have to escape each of the with another backslash. But, then the shell will see the sequence "\\" within double quotes, where the backslash keeps its special meaning, and will just replace those two characters with a single backslash. The way you are using single and double quotes, the shell will be also doing that when setting the COMM variable. You can prevent that by reversing your usage of single and double quotes (and getting rid of that useless use of "echo" is a good idea too).
Code:
COMM='find /path/to/dir -type f \\( -name "*.gz" -o -name "*.log" \\) -mtime + ${days} -exec rm -fr {} \\;' |
Thanks for reply.
Tried to escape using one more \ and got rid of echo too. ${days} gets printed literally instead of its value. Escaping the curly brackets and $ didnt work too. Also Assigned the command to double quoted variable with escaping \ with one more \. Again the original issue of \ missing :( |
Sorry, I missed that there was a ${days} expansion in that assignment of the COMM variable. You would need to keep that outside of the single quotes:
Code:
COMM='find /path/to/dir -type f \\( -name "*.gz" -o -name "*.log" \\) -mtime + '${days}' -exec rm -fr {} \\;' Code:
COMM="find /path/to/dir -type f \\\\( -name '*.gz' -o -name '*.log' \\\\) -mtime + ${days} -exec rm -fr {} \\\\;" |
Bingo!!
Many Thanks, Sir!! |
All times are GMT -5. The time now is 04:55 PM. |