I try to do string replacement in linux shell,
str=2011/10/10
echo "$str"
a=${str//\//\_}
echo $a
It can execute when I invoke command : ./test.sh But if I run it in nohup mode, using command : nohup ./test.sh &
It says that ./test.sh: 8: Bad substitution
What's wrong here ?
Thanks
Since you have no #!/bin/bash
at the top of your script, the 'nohup' command is using /bin/sh and your system's /bin/sh isn't BASH. Your first and third lines where you assign 'str' and 'a' are not correct Bourne syntax.
Since you likely want to use BASH and not a shell that uses strict Bourne syntax, you should add a #! line at the top of your script like this:
#!/bin/bash
str=2011/10/10
echo "$str"
a=${str//\//\_}
echo $a