Bash文件脚本转义用户输入(Bash file script escaping user input)

编程入门 行业动态 更新时间:2024-10-27 18:32:28
Bash文件脚本转义用户输入(Bash file script escaping user input)

这个bash脚本在Mac终端上运行时,需要询问用户输入,然后需要检查给定文件中是否存在字符串"PLACEHOLDER_BACKEND_NAME="user-input" ,如果不存在,则应退出脚本。

echo -e "${YELLOW}enter app name${WHITE}" read name line=grep $name /path/to/file/entrypoint.sh if [[ line != "PLACEHOLDER_BACKEND_NAME=\"$name\"" ]] ; then exit 1 fi

它需要很多调整,因为我不太熟悉bash脚本。 有什么建议么? 谢谢

This bash script when run on Mac terminal, it needs to ask for user input, then it needs to check if a a string "PLACEHOLDER_BACKEND_NAME="user-input" exists in a given file and if not it should exit the script.

echo -e "${YELLOW}enter app name${WHITE}" read name line=grep $name /path/to/file/entrypoint.sh if [[ line != "PLACEHOLDER_BACKEND_NAME=\"$name\"" ]] ; then exit 1 fi

It needs much tuning as I am not very familiar with bash scripts. any suggestions? thx

最满意答案

您的代码需要稍微调整一下:

echo -e "${YELLOW}enter app name${WHITE}" read -r name if ! grep -q PLACEHOLDER_BACKEND_NAME="\"$name\"" /path/to/file/entrypoint.sh; then exit 1 fi

Your code needs a little tweaking:

echo -e "${YELLOW}enter app name${WHITE}" read -r name if ! grep -q PLACEHOLDER_BACKEND_NAME="\"$name\"" /path/to/file/entrypoint.sh; then exit 1 fi

更多推荐

本文发布于:2023-08-06 05:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1443984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   文件   用户   Bash   file

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!