markdownshell脚本最佳实践(代码片段)

author author     2022-12-16     235

关键词:


## From the top
```
#!/usr/bin/env bash

set -o errexit 
set -o pipefail
```

First line (shebang) tell us which interpreter to use. We recommend using `#!/usr/bin/env bash` for [portability](https://en.wikipedia.org/wiki/Shebang_%28Unix%29#Portability). Different \*nixes put `bash` in different places, so using `/usr/bin/env` is a workaround to find the first `bash` found on the `PATH`. (**Avoid using `sh`**)

Next, you must **always** use a `set -o errexit` or `set -e` for short. This option makes your script exits whenever a command returned with non-zero status code.

`set -o pipefail` help you avoid expression like `error here | true` to be succeed. (This is not what you want)

Some other options are:
* `set -o xtrace` or `set -x` for short: print every expression before execute it. It really helpful when debugging/build script.

## STDOUT vs STDERR
All error messages should go to `STDERR`
Example: `echo "ERROR OCCUR" > &2`

## Variables
To declare new variable, you should use `declare var=value`. 

## Constants
Simply use `readonly var=value`.

## Conditionals
We prefer to user double square brackets `[[ ]]` in statement because those provide cleaner syntax, easy to use.
Inside `[[ ]]` we allowed to user regular expression.

## Command substitution
Use `$(command)` instead of backticks.

## References
* [Shell style guide](https://google.github.io/styleguide/shell.xml)

arthas入门最佳实践(代码片段)

一、入门步骤1、安装https://arthas.gitee.io/install-detail.html上述命令会下载启动脚本文件as.sh到当前目录curl-Lhttps://alibaba.github.io/arthas/install.sh|shoras.sh启动curl-skhttps://arthas.gitee.io/arthas-boot.jar-o~/.arthas-boot. 查看详情

markdownshell特殊变量:shell0,#,*,@,?,$和命令行参数(代码片段)

查看详情

[转]jenkinspipeline插件十大最佳实践(代码片段)

...oovy中的领域特定语言(DSL),Pipeline插件使Pipelines可以有脚本来定义,并且提供了非常强大的方法来开发复杂的、多步DevOpsPip 查看详情

web最佳实践阅读总结(代码片段)

...网站整体性能差,没有意识到应用诸如缓存,动态加载,脚本压缩,图片压缩等提高性能技术推荐做法:压缩样式表和脚本文件减少HTTP请求次数简洁和符合W3C标准的HTML和CSS代码能减少浏览器解析的时间,加快渲染过程页面请求... 查看详情

markdownshell用于使用docker运行npm,composer和php之类的东西。(代码片段)

查看详情

javascript最佳实践(代码片段)

查看详情

markdowndevops最佳实践(代码片段)

查看详情

textlaravel最佳实践(代码片段)

查看详情

csscss最佳实践(代码片段)

查看详情

markdownfirebasefirestore最佳实践(代码片段)

查看详情

textrest最佳实践(代码片段)

查看详情

text最佳实践承诺(代码片段)

查看详情

markdownvuejs最佳实践指南(代码片段)

查看详情

制作容器镜像的最佳实践(代码片段)

...的关于镜像制作的相关文章总结出来的.包括通用的容器最佳实践,java,nginx,python容器最佳实践.最佳实践的目的一方面保证镜像是可复用的,提升DevOps效率,另一方面是为了提高安全性.希望对各位有所帮助.本文分为四部分内容,分别... 查看详情

阿里开源那个牛哄哄问题排查工具竟然不会用?最佳实践来了!(代码片段)

...装https://arthas.gitee.io/install-detail.html上述命令会下载启动脚本文件as.sh到当前目录,执行方式:curl-Lhttps://aliba 查看详情

activity的最佳实践(代码片段)

文章目录Activity的最佳实践知晓当前是在哪一个Activiy随时随地退出程序启动Activity的最佳写法Activity的最佳实践知晓当前是在哪一个Activiy创建一个BaseActivity类,继承AppCompatActivity类.重写onCreate方法openclassBaseActivity:AppCompatActivity()overr... 查看详情

最佳实践:创建脚本编辑器

】最佳实践:创建脚本编辑器【英文标题】:Bestpractice:creatingascripteditor【发布时间】:2016-02-0212:37:41【问题描述】:我已经开发了自己的脚本语言来用一些独特的逻辑查询我的数据源,我想向我的用户提供这个脚本,并希望在... 查看详情

markdown表单设计最佳实践(代码片段)

查看详情