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
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.sh you 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
sh scriptname then sh is a link to dash in ubuntu. +1 to @Chris$ foo=foobarfoobar
$ echo ${foo}/bar/baz
foobarfoobar/bar/baz
Just that you have the braces in the wrong place, but then I am no expert at BASH, so perhaps this isn't the effect you're going for..
//. I don't think he wants to append bar/baz to his variable. He is looking to replace occurrences of bar with baz so that his output looks like foobazfoobaz
echo $0anduname -aon the command line and add it to your question. Also, if you can paste the error message from the shell. Do./script.shon the command line and show the output in your question