0

I am using following in my shell script

LOGDATE='date +%m%d%y_%H%M'

and then calling same as following in the same shell script

$LOGDATE

but it is printing output as following

echo $LOGDATE

date +%m%d%y_%H%M

could anyone tell what am i doing wrong?

JB88
  • 37
  • 6

1 Answers1

3

You've mistaken single quote character ', used for escaping strings (no variable is expanded, backslash doesn't escape character, and delimiters are ignored) for backtick character ` that executes the content in a subshell and returns stdout as a string.

LOGDATE=`date +%m%d%y_%H%M`

Newer bash versions also allow the syntax

LOGDATE=$(date +%m%d%y_%H%M)

It may be considered more readable and allows for easier nesting of expressions:

xvan
  • 4,554
  • 1
  • 22
  • 37