Solved

Concat strings in unix using multiple variables

Posted on 2009-07-10
2
965 Views
Last Modified: 2013-12-26
In my shell script I am trying to get a subject line (string)

I have already:
today_dt=`date +%m%d%Y`

I need to create a string $mysubjectline = "Files for" + today_dt +"for PROJECT1"

and then do :
#tar -cvf dailyfiles.tar file1.html file2.csv  
#uuencode dailyfiles.tar dailyfiles.tar | mail -s $mysubjectline tom.dick@harry.com

Whats the best way to concat my string with the date variable and use in subjectline
0
Comment
Question by:LuckyLucks
2 Comments
 
LVL 12

Expert Comment

by:kevin_u
ID: 24824998
today_dt=`date +%m%d%Y`
mysubjectline="Files for $today_dt for PROJECT1"
tar -cvf dailyfiles.tar file1.html file2.csv  
uuencode dailyfiles.tar dailyfiles.tar | mail -s "$mysubjectline" tom.dick@harry.com

variables are expanded inside of double quoted strings, so concatenation is not usually needed.

I also put quotes around $mysubjectline so that the multiple words in the subject are treated as one argument to the -s option of mail.
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 24825253
the script below will do the job

#!/usr/bin/ksh
today_dt=`date +%m%d%Y`
tar -cvf dailyfiles.tar file1.html file2.csv  
uuencode dailyfiles.tar dailyfiles.tar | mail -s "Files for $today_dt for PROJECT1" tom.dick@harry.com

no need for this line since it could be put directly as the subject of mail

mysubjectline="Files for $today_dt for PROJECT1"
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question