bash : Bad Substitution
#!/bin/bash
jobname="job_201312161447_0003"
jobname_pre=${jobname:0:16}
jobname_post=${jobname:17}
This bash script gives me Bad substitution error on ubuntu. Any help will be highly appreciated.
Solution 1:
The default shell (/bin/sh
) under Ubuntu points to dash
, not bash
.
me@pc:~$ readlink -f $(which sh)
/bin/dash
So if you chmod +x your_script_file.sh
and then run it with ./your_script_file.sh
, or if you run it with bash your_script_file.sh
, it should work fine.
Running it with sh your_script_file.sh
will not work because the hashbang line will be ignored and the script will be interpreted by dash
, which does not support that string substitution syntax.
Solution 2:
I had the same problem. Make sure your script didnt have
#!/bin/sh
at the top of your script. Instead, you should add
#!/bin/bash