Thursday, May 26, 2022

[SOLVED] How to pass blank parameters to a script called in crontab (Linux)

Issue

I am trying to pass a blank parameter using double quotes, "", but it just gets ignored. All parameters after the blank parameter end up in the wrong position in the called script.

My crontab entry looks like:

* * * * * myscript.sh A B "" C D

Parameters A and B end up in the correct position in myscript.sh, but D and E end up in parameter positions 3 and 4 in myscript.sh (instead of positions 4 and 5).

How can I fix this?


Solution

I would suggest (without having tested it) the following:

* * * * * /usr/bin/env bash -c 'myscript.sh A B "" C D'

or alternatively just

* * * * * bash -c 'myscript.sh A B "" C D'


Answered By - patate
Answer Checked By - Cary Denson (WPSolving Admin)