2

This might be considered abuse by some, but perhaps I (and others) can learn something here.

I'm using vscode and recently when editing a crontab file I was annoyed that there was no syntax highlighting1. One immediate workaround is to use shell script highlighting. But vscode does not load this highlighting scheme on extension-less files if they don't start with a shebang.

So given that a crontab file is not an executable (I'm assuming the file is placed in /etc/cron.d on an Ubuntu system owned by root with permissions 644) could I just place #!/bin/bash at the top of the file? This certainly works in setting the correct highlighting scheme in vscode and the cronjob runs just fine as usual. And to the best of my knowledge the shebang is only parsed if the file is executable.

So the question is, how bad is this (from a best practice perspective) and do I open up for unforeseen problems down the road (functional and/or security related)?

Note: this is not a duplicate of this question and others like it, because I want to place a (useless) shebang in the crontab file itself.

1Note: there is an extension for crontab highlighting, but it has other limitations at the moment not relevant here.

glaux
  • 121
  • 3

1 Answers1

2

According to man -s 5 crontab:

Lines whose first non-space character is a hash-sign (#) are comments, and are ignored.

A shebang just gives a data file a strange comment on line 1.

There are various crontab extensions for environment, but it seems unlikely that the comments rule would be modified (e.g. with #pragma-type settings).

Best not make the file executable, though. All those * would expand in a very unpleasant way.

Paul_Pedant
  • 8,228
  • 2
  • 18
  • 26