gpt4 book ai didi

bash - 在 Bash 中使用空格

转载 作者:行者123 更新时间:2023-11-29 09:09:34 25 4
gpt4 key购买 nike

我需要找到在 case 模式中使用空格的解决方案。我有这个功能 case

  setParam() {
case "$1" in
0624)
# do something - download file from url
;;
del-0624)
# do something - delete file from local machine
exit 0
;;
# Help
*|''|h|help)
printHelp
exit 0
;;
esac
}

for PARAM in $*; do
setParam "$PARAM"
done

Paramter "0624" 用于从 url 下载文件的运行函数。参数"del-0624"用于删除 native 文件。

问题:可以使用参数"del 0624"(带空格)吗?我在 case 中的参数空间有问题。

最佳答案

case 中需要使用双引号。此外,脚本应作为 ./script "del 0624" 运行。

setParam() {
case "$1" in
"0624")
# do something - download file from url
;;
"del-0624")
# do something - delete file from local machine
exit 0
;;
"del 0624")
# do something - delete file from local machine
exit 0
;;
# Help
*|''|h|help)
printHelp
exit 0
;;
esac
}

关于bash - 在 Bash 中使用空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29470418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com