문제

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top