Solved

Concat strings in unix using multiple variables

Posted on 2009-07-10
2
963 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now