I was recently running a cron job using crontab -e and I found some strange behaviour. The following command doesn't work:
* * * * * cp /home/username/{*txt,*pdf} /home/username/test/
but the following does
* * * * * cp /home/username/*txt /home/username/test/
while both commands work in bash.
Why am I not able to use curly brackets in cron?
In languages like C curly braces ( {} ) are used to create program blocks used in flow control. In Python, curly braces are used to define a data structure called a dictionary (a key/value mapping), while white space indentation is used to define program blocks.
The end of the variable name is usually signified by a space or newline. But what if we don't want a space or newline after printing the variable value? The curly braces tell the shell interpreter where the end of the variable name is.
Basically the curly braces {} are the another way for creating objects in javascript. This is equivalent to the "new Object()" syntax. Follow this answer to receive notifications.
I suppose cron
uses the sh
shell to run your commands by default. sh
does not support curly-brace wildcards.
IIRC, you can add to your crontab the following line:
SHELL=/bin/bash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With