3

I want to create a echo statement in a Bash script that will say "Today is (current date and time)".

so far I've tried:

today=date

echo Today is $today

but no luck

αғsнιη
  • 35,660
Justin
  • 2,121

2 Answers2

4

To embed commands into other ones, either wrap them in `` or in $().

Examples:

echo Today is $(date)
echo Today is `date`
s3lph
  • 14,314
  • 11
  • 59
  • 82
0

the right one is:

today=$(date)
echo Today is $today

In other words, use the variable=$(commands) syntax, it will save the result of command into variable and so if you want to printout the what was the result? you can use:

echo $variable

here is the similar example http://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/

αғsнιη
  • 35,660