Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Fails to understand %, \%, and \\ #19

Open
andersk opened this issue Aug 2, 2014 · 2 comments
Open

Fails to understand %, \%, and \\ #19

andersk opened this issue Aug 2, 2014 · 2 comments

Comments

@andersk
Copy link

andersk commented Aug 2, 2014

From crontab(5) (cron 3.0pl1-124.1ubuntu1):

The  ``sixth'' field (the rest of the line) specifies the command to be
run.  The entire command portion of the line, up  to  a  newline  or  %
character, will be executed by /bin/sh or by the shell specified in the
SHELL variable of the crontab file.  Percent-signs (%) in the  command,
unless escaped with backslash (\), will be changed into newline charac‐
ters, and all data after the first % will be sent  to  the  command  as
standard  input.  There  is  no way to split a single command line onto
multiple lines, like the shell's trailing "\".

Although this is not specifically documented, the source indicates that a backslash can also be used to escape another backslash (but not any other character, except after the first %).

@pbyrne
Copy link
Owner

pbyrne commented Aug 2, 2014

Interesting. I've never run into that before. If I'm properly reading properly, I should be treating % and \ in the command like so:

  • foo%bar will perform foo and send bar to STDIN
  • foo % bar will perform foo and send bar to STDIN (preserving whitespace)
  • foo%bar%baz will perform foo and send bar\nbaz to STDIN
  • foo \% bar will perform foo % bar
  • foo \\ bar will perform foo \ bar

@andersk, care to correct me if I'm misunderstanding? Also, thanks for this bug report!

@danielmotaleite
Copy link

@pbyrne that is correct

the % is a trap for many people when using cron, specially in things like date +%Y%m%d , that will fail and people don't understand why

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants