Skip to content
Advertisement

crontab shell script starts another script: remove char error

I want to run a shell script through crontab which does something and then runs another shell script which checks a certain folder for certain files and creates a directory for each file. The first script “my_crontab.sh” looks like this:

JavaScript

Crontab executes “my_crontab.sh” and “start.sh” gets also called (I know from the crontab log file)

This is what “start.sh” looks like:

JavaScript

now I’m getting the error: /bin/sh: 7: /home/myusername/myfolder/start.sh: Bad substitution

I already tried folder=${ i:0:-4 } instead, but that’s also not working. Any ideas how to fix it?

Advertisement

Answer

Continuing from the comment, your Bad Substitution in start.sh is caused because you are leaving spaces in line 7 between the braces and your variable name and substitution, (e.g. "${ i/.jpg/ }" should be "${i/.jpg/}". Line 4 is problematic because -ne expects integer expressions on both sides and there is no guarantee the command substitution will comply (it should with wc -l) but it is not guaranteed. You are better served writing start.sh something similar to:

JavaScript

note: the counter cnt is just used to output "nothing to do" in the event there are no .jpg files found, if that isn’t needed, just delete all lines referring to cnt.

Advertisement