I'm trying to write a script that sorts some files, and I got it working manually in the shell (Debian, seems to be dash), but when I run the same code as a script I get "Bad substitution" from line 2 and 3;
#!/bin/bash
LAST_MONTH="${date +'%Y%m' -d 'last month'}"
LAST_MONTH_HYPHEN="${date +'%Y-%m' -d 'last month'}"
Everything I found on SO seemed to be related to different shells, so I've tried #!/bin/sh
as well as #!/bin/bash
. I've also tried running the script as ./filesorter.sh
, bash filesorter.sh
and sh filesorter.sh
, and every permutation gives me some variation on the same "bad substitution" theme
filesorter.sh: line 2: ${date +'%Y%m' -d 'last month'}: bad substitution
filesorter.sh: line 3: ${date +'%Y-%m' -d 'last month'}: bad substitution