Home > Enterprise >  Script not reading out the variable - why not though?
Script not reading out the variable - why not though?

Time:10-24

#!/bin/sh
#Saying the system time out loud

time= date  "%T"

say The current time now is, $time. Bye.

The script is printing out the time, not saying it.

CodePudding user response:

Try using a HereDoc like this ...

bash-3.2$ cat <<EOT
> The current time is now, `date  "%T"`
> EOT
The current time is now, 19:49:16

CodePudding user response:

Okay, this worked. Thank you. :) Appreciate the help!

#!/bin/sh
#Saying the system time out loud

time=$(date  "%T")
say The time is now $time. Thank you.

CodePudding user response:

time= date "%T"

you want to set time to the stdout of the date command, so you want $(date %T) (the double quotes around %T aren't necessary as % doesn't have a special meaning in this context).

printing out the time, not saying it."

Fixing your syntax , it works for me and recently vocalized the time as "twenty one forty six twenty seven" for example.

time=$(date  %T)
say the time is $time
  • Related