I newbie in bash scripting but i don’t uderstand why it’s not work
#!/bin/bash
foo=foobarfoobar
echo ${foo//bar/baz}
bad substitution error on line 3
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That substitution works fine in Bash 4.2.8 (and looks fine according to the documentation).
My best guess would be that you’re not actually using Bash – how are you invoking the script? If you’re doing
sh script.shyou may well be running it with Dash or something similar (and Dash does indeed give a substitution error on line 3). Try explicitly running it with Bash (bash script.sh).If it turns out you are actually using Dash, there’s some useful information on the differences and how to go back to using Bash (if you want to) here: https://wiki.ubuntu.com/DashAsBinSh