0

Running on MacOS. Learning bash so bear with me. I have a simple bash script that looks like this:

#!/bin/bash

RUN_DATE=`date +%Y_%m_%d`
python3 /path/to/some/builder.py --date=$RUN_DATE

Where I have a program called builder.py and it takes an date input. I want to write a bash script that sets $RUN_DATE to whatever the date it is at the time of the run. It will be read in Python as a string input. However, I get the following error:

RUN_DATE=`date +%Y_%m_%d`
         ^
SyntaxError: invalid syntax

Is there something obvious I'm overlooking to get this to work?

  • 1
    Sure you're running that with bash and not some other program? – Shawn Oct 01 '21 at 06:39
  • Are you trying to run the bash script with python? If so, you might want to try running it with bash like this: ```./YOUR_SCRIPT_NAME.sh``` – tomerpacific Oct 01 '21 at 06:40
  • 1
    As an aside, you want `$(date +%Y_%m_%d)` instead of the obsolescent backtick syntax from the 1990s. Try http://shellcheck.net/ for checks against many common beginner errors. – tripleee Oct 01 '21 at 06:45
  • 1
    As a further aside, Python itself is quite capable of checking the date; `from datetime import datetime` and then `date = datetime.utcnow().strftime("%Y_%m_%d")` – tripleee Oct 01 '21 at 06:46

0 Answers0