0

I have written a script that runs fine when I execute it, but when I tried to run it as a cronjob, I get a SyntaxError: invalid syntax error.

The line in question is

folder=$(find $folder -maxdepth 1 -type d -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- d" ")

The caret (^) sign that indicated where the error was was under the $ in folder=$(find

Why did I only get the error from the cronjob but not when I manually run the script?

Rayne
  • 14,247
  • 16
  • 42
  • 59
  • Looks like your cron job is running with /bin/sh, not bash. `$()` is a bash construct, the rough equivalent of which is backticks in sh. Put a shebang line `#!/usr/bin/env bash` at the top of your script to make sure it is invoked with bash. – codeforester Apr 03 '18 at 04:20
  • @codeforester Any even vaguely recent shell should support `$( )` -- it's been in POSIX [since at least 2004](http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03). That looks like a Python error message, so I think something's even more messed up than that. Rayne, what's the rest of the script? BTW, I don't think this is actually a duplicate. – Gordon Davisson Apr 03 '18 at 04:53

0 Answers0