最近一直在写 .net core,它有诸多优点我且不提,我实在头痛于手写注入服务时的模式化代码,因此动了心思要写个小脚本帮我自动化一些事情。我的想法是告诉我要加入的 ServiceName, 指定一个 Controller然后脚本自动在这个 Controller 里声明一个 private readonly 属性,自动修改类的construction 函数,自动注入这个服务,并在construction 函数体写上 _serviceName = serviceName;
在第一步,注入 private readonly 属性那里,我就绊了个跟头。用 sed 匹配到某行,在它之前,或者之后插入数据是简单的。但我匹配到 public class xxxController 这行之后是单独一行 {,而我要加的变量要放到 {这行之后。网上一通搜索,试图找到定位到某行之后N行的命令,然而并没有这样的命令。然而功夫不负有心人,我最后还是找到了一个解决方案,那就是
sed '/pattern/!b;n;n;i\something'
具体解释见
Reference
其实很简单,但因为网上有流传很广的教程并不适用于最新的 ubuntu 20.04,造成我也走了一点弯路。
certbot-auto 官方已停止维护,但网上广为流传的教程仍然推荐使用 certbot-auto 来生成证书。这是问题的根源。正确的姿势是这样的
sudo apt install certbot
sudo certbot certonly --manual -d *.yourdomain.com -d youdomain.com --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
照提示一步一步来就好了。是不是超级简单?
, change the first letter of the value of the variable to lowercase, ,, change the value of the whole variable to lower case.
$ test='HELLO'
$ echo $test
HELLO
$ echo ${test,}
hELLO
$ echo ${test,,}
hello
$ test=${test,,}
$ echo ${test^}
Hello
$ echo ${test^^}
HELLO
#!/bin/bash
git push
currentbranch=`git branch --show-current`
if [ "${currentbranch}" == "local" ]; then
git checkout develop
git merge local
git push
elif [ "${currentbranch}" == "develop" ]; then
git checkout local
git merge develop
git push
fi
git checkout $currentbranch
Don't ask why I wrote this foolish script. I have to do it 😀
I originally thought the later should be used. I was wrong.