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.
#!/bin/sh var="$1"; OUTPUT=$(echo ${$var,,}); echo $OUTPUT
我尝试了所有可能的组合,包括转义某些字符。
我只是不能让 shell 输出我的脚本参数小写。
错误:
createmodule.sh: 26: createmodule.sh: Bad substitution
为什么是这样?
有一个错误,试试这个:
#!/bin/bash var="$1" OUTPUT=${var,,} echo $OUTPUT
你有一个$多余的。
$
如讨论中所见,sh script如果您不确定所需的 shell 是否真的是sh一个,则永远不要调用脚本。更好的方法是把好的 shebang 像#!/bin/bash,然后chmod+x script.sh,最后./script.sh
sh script
sh
#!/bin/bash
chmod+x script.sh
./script.sh