Bad substitution Error in Linux

By | June 16, 2016

I was trying to run a script from a shell, it executed properly. But when I was running this script in

cron, the script does not behave correctly. It runs partially. Then I tried following in cron:

10 10 * * * /data/script1.sh >>/tmp/script1.log 2>&1

After the cron finished executing, I looked up in /tmp/script1.log. It shows:

/data/script1.sh:51:/data/script1:Bad substitution

After some research , I found that cron, by default, runs using /bin/sh shell. Then, I checked my

login shell from /etc/passwd. It was /bin/bash.

So, I added #! /bin/bash at the top of the script. Then, script ran properly when running from cron.

The reason for the script not working properly earlier was that there were some commands inside

the script which does not supported by /bin/sh.

Share itShare on FacebookEmail this to someoneTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

Leave a Reply

Your email address will not be published. Required fields are marked *

Current month ye@r day *