On 08May2020 20:32, Samuel Sieb <sam...@sieb.net> wrote:
On 5/8/20 4:32 PM, Cameron Simpson wrote:
On 08May2020 11:15, Robert Moskowitz <r...@htt-consult.com> wrote:
I added inserting a Date: line and switched to using sed:

local]# cat mycron
#!/bin/sh

currentDate="$(date +'%a %b %d %T %Y')"

You don't need the double quotes. The shell parser recognises the assignment statement _before_ breaking things on whitespace.

That's not entirely true. It will compress whitespace in the output if you don't use quotes.
$(date +'%a %b %d %T %Y')
$(date +'%a  %b  %d  %T  %Y')
will end up exactly the same without the double quotes around it.

It is entirely true. The collapsing happens when you _use_ the values:

   # all safe and reliable
   $ a=$( date +'%a %b %d %T %Y')
   $ b=$( date +'%a  %b  %d  %T  Y')
   $ c=$b

   # unquoted use
   $ echo $a
   Sat May 09 14:37:07 2020
   $ echo $b
   Sat May 09 14:37:15 2020
   $ echo $c
   Sat May 09 14:37:15 2020

   # quoted use
   $ echo "$a"
   Sat May 09 14:37:07 2020
   $ echo "$b"
   Sat  May  09  14:37:15  2020
   $ echo "$c"
   Sat  May  09  14:37:15  2020

The variable $b contains the multiple spaces you put in your date format. But they only survive is you quote the variable when you use it.

So the assignment statements do not need the quotes because of how the parsing is done.

Word separation happens in command _usage_ if you don't quote because the shell is in some ways a macro language. But $b contains the multiple spaces unharmed, you just have to not use it in a destructive way (== unquoted).

Cheers,
Cameron Simpson <c...@cskk.id.au>
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org

Reply via email to