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 fiIt 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 fiYour 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更多推荐
发布评论