Passing a file name to a variable

Below is the command

mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_`date "+%Y%m%d%H%M%S" | tr '[a-z]' '[A-Z]'`.TXT

it is changing the file name to a different name according to time stamp dynamically. I want to capture that dynamic file name present in the directory to a variable .

After that i want to call a java program in the same shell script which will use this variable(i.e dynamic file name ) as parameter.

please let me know how to capture the dynamic file name present in the directory to a variable, so that i can pass that variable as a parameter in my java script which is called in the same shell script itself.

Please help asap.

The easiest way is to create the variable first and then use it in the mv command:

DATVAR=$(date "+%Y%m%d%H%M%S")
mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_$DATVAR.TXT

Please be aware that I replaced the deprecated backticks by the $(...) "command substitution".
BTW, the date is all digits - so, why the tr ?

A second way might be

mkfifo YYY
echo mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_$(date "+%Y%m%d%H%M%S" | tee YYY).TXT & DATVAR="$(cat YYY)"
echo $DATVAR
20161020162732
rm YYY

of which I can't tell if its reliable and sensible enough for production systems.

thanks Rudic for the quick reply.
its a existing code in production so i think i cannot remove tr command now, even though i am sure that removal of that won't create any issue.

but can we capture the the dynamic name including tr command by following the first
solution.

i mean can we write something like this

DATVAR=$(date "+%Y%m%d%H%M%S|`'tr '[a-z]' '[A-Z]'`")

mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_$DATVAR .TXT

so i need to pass FTPYMNTE_$DATVAR.TXT as a parameter in java program right?
thanks in advance

Yes to both.
Why don't you assign the entire destination file name to a variable, then?

did you mean something like this

DATVAR=$(FTPYMNTE_|date "+%Y%m%d%H%M%S|`'tr '[a-z]' '[A-Z]'`"|.TXT)

mv AP_FLEXCUBE_INTERFACE10.txt $DATVAR

please correct if any syntax error and the back ticks where it need to be placed

Try

DATVAR=FTPYMNTE_$(date "+%Y%m%d%H%M%S" | tr '[a-z]' '[A-Z]').TXT

Pipes are used to connect processes by tying one's stdout to te next's stdin.

Strings are concatenated by writing them one after the other in the assignment statement. Should spaces exist within, enclose the entire assignment string in quotes.

Thanks a lot for your reply. no spaces aren't used.:):):b: