相关疑难解决方法(0)

Bash Templating:如何使用Bash从模板构建配置文件?

我正在编写一个脚本来自动为我自己的web服务器创建Apache和PHP的配置文件.我不想使用像CPanel或ISPConfig这样的任何GUI.

我有一些Apache和PHP配置文件的模板.Bash脚本需要读取模板,进行变量替换并将解析后的模板输出到某个文件夹中.最好的方法是什么?我可以想到几种方法.哪一个是最好的还是有更好的方法可以做到这一点?我想在纯Bash中做到这一点(例如在PHP中很容易)

1)如何在文本文件中替换$ {}占位符?

template.txt:

the number is ${i}
the word is ${word}
Run Code Online (Sandbox Code Playgroud)

script.sh:

#!/bin/sh

#set variables
i=1
word="dog"
#read in template one line at the time, and replace variables
#(more natural (and efficient) way, thanks to Jonathan Leffler)
while read line
do
    eval echo "$line"
done < "./template.txt"
Run Code Online (Sandbox Code Playgroud)

顺便说一句,如何在此处将输出重定向到外部文件?如果变量包含引号,我是否需要逃避某些事情?

2)使用cat&sed替换每个变量的值:

给出template.txt:

The number is ${i}
The word is ${word}
Run Code Online (Sandbox Code Playgroud)

命令:

cat template.txt | sed -e "s/\${i}/1/" | sed -e "s/\${word}/dog/"
Run Code Online (Sandbox Code Playgroud)

对我来说似乎不好,因为需要逃避许多不同的符号,并且对于许多变量,这条线太长了.

你能想到其他一些优雅而安全的解决方案吗?

bash templates templating

118
推荐指数
15
解决办法
10万
查看次数

为什么 flutterfire 配置不替换我的旧 GoogleService-Info.plist 文件?

当我第一次运行flutterfire configure我的 flutter 应用程序时,生成了 4 个文件。firebase_options.dartgoogle-services.jsonfirebase_app_id_file.jsonGoogleServices-Info.plist

\n

当我尝试flutterfire configure再次使用将我的应用程序链接到我的应用程序的开发版本(遵循此线程)时,系统仅提示我更改其中的 3 个文件,如下所示:

\n
\n

google-services.json 文件已存在,但用于不同的 Firebase 项目 (betacentre-dev)。您想将其替换为 Firebase 项目 Thinking-digit-343408 吗?\xc2\xb7 是

\n
\n

选择yes所有这些后,只有 GoogleService-Info.plist 没有更改,但这对于 firebase 的工作显然至关重要(因为flutterfire configure首先添加了它,并且在本指南本指南中都引用了它,并且它包含标识符对于我的 firebase 项目,并且我的应用程序仍然与原始项目通信)。

\n

这是一个错误吗?为什么会这样?

\n

plist ios firebase flutter

5
推荐指数
1
解决办法
781
查看次数

标签 统计

bash ×1

firebase ×1

flutter ×1

ios ×1

plist ×1

templates ×1

templating ×1