Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试在 linux shell 中进行字符串替换,
str=2011/10/10 echo "$str" a=${str//\//\_} echo $a
它可以在我调用命令时执行:./test.sh 但是如果我在 nohup 模式下运行它,使用命令:nohup ./test.sh &
它说 ./test.sh: 8: 错误替换
这里有什么问题?
谢谢
#!/bin/bash由于您的脚本顶部没有,因此“nohup”命令正在使用 /bin/sh 并且您系统的 /bin/sh 不是 BASH。您分配“str”和“a”的第一行和第三行不是正确的 Bourne 语法。
#!/bin/bash
由于您可能想要使用 BASH 而不是使用严格 Bourne 语法的 shell,因此您应该添加 #! 脚本顶部的行,如下所示:
#!/bin/bash str=2011/10/10 echo "$str" a=${str//\//\_} echo $a