KSH: Variables containing double quotes
Posted
by
nitrobass24
on Stack Overflow
See other posts from Stack Overflow
or by nitrobass24
Published on 2012-10-01T20:06:56Z
Indexed on
2012/10/01
21:38 UTC
Read the original article
Hit count: 210
I have a string called STRING1 that could contain double quotes.
I am echoing the string through sed to pull out puntuation then sending to array to count certain words. The problem is I cannot echo variables through double quotes to sed.
I am crawling our filesystems looking for files that use FTP commands. I grep each file for "FTP"
STRING1=`grep -i ftp $filename`
If you echo $STRING1 this is the output (just one example)
myserver> echo "Your file `basename $1` is too large to e-mail. You must ftp the file to BMC tech support. \c"
echo "Then, ftp it to ftp.bmc.com with the user name 'anonymous.' \c"
echo "When the ftp is successful, notify technical support by phone (800-537-1813) or by e-mail ([email protected].)"
Then I have this code
STRING2=`echo $STRING1|sed 's/[^a-zA-Z0-9]/ /g'`
I have tried double quoting $STRING1 like
STRING2=`echo "$STRING1"|sed 's/[^a-zA-Z0-9]/ /g'`
But that does not work. Single Qoutes, just sends $STRING1 as the string to sed...so that did not work.
What else can I do here?
© Stack Overflow or respective owner