On 5/9/20 12:41 AM, Cameron Simpson wrote:
On 08May2020 20:32, Samuel Sieb <samuel@xxxxxxxx> wrote:
On 5/8/20 4:32 PM, Cameron Simpson wrote:
On 08May2020 11:15, Robert Moskowitz <rgm@xxxxxxxxxxxxxxx> 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).
I am having problems taking out the '
I set up a little script and run it:
$ cat mcron
#!/bin/sh
currentDate="$(date +'%a %b %d %T %Y')"
echo "From cron@localhost $currentDate"
[rgm@lx140e ~]$ ./mcron
From cron@localhost Sun May 10 13:28:59 2020
Then I take out the '
$ cat mcron
#!/bin/sh
currentDate="$(date +%a %b %d %T %Y)"
echo "From cron@localhost $currentDate"
[rgm@lx140e ~]$ ./mcron
date: extra operand ‘%b’
Try 'date --help' for more information.
From cron@localhost
I tried taking out the " as in your example and still get the error.
So I tried the %_b from the man and not dice:
$ cat mcron
#!/bin/sh
currentDate=$(date +%_a%_b%_d%_T%_Y)
echo "From cron@localhost $currentDate"
[rgm@lx140e ~]$ ./mcron
From cron@localhost SunMay1013:34:282020
So I am missing something compared to your experience.
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxxx