-1
#!/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.

Janeway
  • 19
  • 5
  • 1
    Script is not correct. Check syntax at shellcheck.net – LMC Oct 24 '22 at 02:40
  • Thank you for the response. That is a handy site. Looks like this is the corrected script? Still not working though! #!/bin/sh #Saying the system time out loud var time=date +"%T" say The current time now is, "$(time)". Bye. – Janeway Oct 24 '22 at 02:53

4 Answers4

1

You don't need to assign the variable as you can just include the output of date like this

#!/bin/sh
#Saying the system time out loud
say "The time is now $(date +%T). Thank you."
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
0

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
Red Cricket
  • 9,762
  • 21
  • 81
  • 166
  • 1
    the backtick syntax is discouraged nowadays in favor of `$(...)`. however it's worth noting that `say` will work with standard input, but only if command line arguments are not supplied, so a heredoc with command substitution would be an alternative – erik258 Oct 24 '22 at 02:51
  • 2
    Yes good point, usually. I noticed the OP's shebang was `/bin/sh` which may or may not be linked to bash. I just wanted to be Borne Shell compatible just in case. – Red Cricket Oct 24 '22 at 02:53
0

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
erik258
  • 14,701
  • 2
  • 25
  • 31
  • Thank you. Not getting vocalization still. ./currenttime.sh: line 4: date+%T: command not found real 0m0.001s user 0m0.000s sys 0m0.000s This is the response now. – Janeway Oct 24 '22 at 02:58
  • I added my exact commands. You really need to get the syntax right on this for it to work the way you want. `real 0m0.001s user 0m0.000s sys 0m0.000s ` this means you're *invoking* the `time` command wich means you have a space somewhere in your `time` setting. – erik258 Oct 24 '22 at 03:35
0

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.
Janeway
  • 19
  • 5