Solved

How to concantenate variables to create a file name?

Posted on 2001-06-28
6
285 Views
Last Modified: 2013-12-06
I want to create a file name in a script by concantenating variables.
      EXAMPLE:   myfile062701.txt
 
The "myfile" and the ".txt" are the same every time on the file received.  The six digits represent the current date.  When I create one variable

THEDATE=" date "+%m%d%y""
echo $THEDATE
062701

When I try to concantenate the date to the rest of the name, I get the literals, not the value.  (i.e. date +%m%d%y)
0
Comment
Question by:clreising
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:ggs54
ID: 6235677
this works on my HP-UX system.


echo myfile`date +%m%d%y`".txt"

yields:

myfile062801.txt

be sure to delimit your date function with backquotes.

Good luck!
0
 
LVL 1

Expert Comment

by:ggs54
ID: 6235679
this works on my HP-UX system.


echo myfile`date +%m%d%y`".txt"

yields:

myfile062801.txt

be sure to delimit your date function with backquotes.

Good luck!
0
 
LVL 11

Expert Comment

by:griessh
ID: 6235731
>> THEDATE=" date "+%m%d%y""
>> echo $THEDATE
>> 062701

That doesn't sound true. You have to evaluate THEDATE to get the date.

THEDATE=" date "+%m%d%y""
echo
date +%m%d%y
echo `$THEDATE`
062801

Like ggs54 said already (just wanted to point out the difference).

======
Werner
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 3

Accepted Solution

by:
interiot earned 100 total points
ID: 6235890
I assume you're using Bash...

Quotes take the string in literally.  To actually execute date, use backticks:

   THEDATE=`date "+%m%d%y"`
   echo myfile${THEDATE}.txt

this works also:

   CATTED="myfile$(date "+%m%d%y").txt"
   echo $CATTED
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 6235944
OK, let's get really picky... the `` syntax is depricated in POSIX, and you have to be careful of quoting, so the only "correct" answer so far is the CATTED= line above.
0
 

Author Comment

by:clreising
ID: 6238798
I am on AIX using ksh.
This is what worked.
Thanks for the input.

THEDATE=`date "+%m%d%y"`
echo $THEDATE
FACILITY="myfile${THEDATE}.txt"
echo $FACILITY    
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 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