I'm new to shell programing, and what I'm trying to do may be a little silly, but I'd like to use ECHO within the shell to build a Perl script that will be later executed by that same shell program. the problem i'm having is how to escape the $ character within the echo line to get what i want, as well as issues of quotes within quotes.
so here's a piece of my shell script
Quote:
# make the date string for yesterday
NOW=$(date -d "1 day ago" '+%y%m%d')
# make a line to put in perl file
echo "$ftp->put("/home/pi/bin/log$NOW.txt") || die $ftp->message;" >> ftplogs.pl
|
if today is Mar 30, then the value of $NOW is 160329 (the day before)
and what I want to go into the file "ftplogs.pl" from line 4 in my script is:
$ftp->put("/home/pi/bin/log160329.txt") || die $ftp->message;
so I need to somehow get "$ftp-put" and "$ftp->message" to be output just as the are, and yet I also want $NOW to be converted to 160329.
so how to I escape $ftp-put and ftp->message so that that's what is produced, and how to I quote this line? single quotes, double quotes? and how to I escape the quotes so that I get quotes in the output file when I want them?
thanks for any advice offered.