New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shell使用 #23
Comments
目录判断
https://stackoverflow.com/questions/4846007/check-if-directory-exists-and-delete-in-one-command-unix 判断目录是否存在
https://www.cyberciti.biz/tips/find-out-if-directory-exists.html |
ps 显示内存排序
ps 根据pid 排序
ps 显示信息案例
https://alvinalexander.com/linux/unix-linux-process-memory-sort-ps-command-cpu ps 实时查看
|
grep 高级技艺
|
Best Practices for Writing Bash Scriptshttps://kvz.io/bash-best-practices.html Use long options (logger --priority vs logger -p). If you're on cli, abbreviations make sense for efficiency. but when you're writing reusable scripts a few extra keystrokes will pay off in readability and avoid ventures into man pages in the future by you or your collaborators. Use set -o errexit (a.k.a. set -e) to make your script exit when a command fails. Then add || true to commands that you allow to fail. Use set -o nounset (a.k.a. set -u) to exit when your script tries to use undeclared variables. Use set -o xtrace (a.k.a set -x) to trace what gets executed. Useful for debugging. Use set -o pipefail in scripts to catch mysqldump fails in e.g. mysqldump |gzip. The exit status of the last command that threw a non-zero exit code is returned. #!/usr/bin/env bash is more portable than #!/bin/bash. Avoid using #!/usr/bin/env bash -e (vs set -e), because when someone runs your script as bash ./script.sh, the exit on error will be ignored. Surround your variables with {}. Otherwise bash will try to access the $ENVIRONMENT_app variable in /srv/$ENVIRONMENT_app, whereas you probably intended /srv/${ENVIRONMENT}_app. You don't need two equal signs when checking if [ "${NAME}" = "Kevin" ]. Surround your variable with " in if [ "${NAME}" = "Kevin" ], because if $NAME isn't declared, bash will throw a syntax error (also see nounset). Use :- if you want to test variables that could be undeclared. For instance: if [ "${NAME:-}" = "Kevin" ] will set Set magic variables for current file, basename, and directory at the top of your script for convenience. Summarizing, why not start your next bash script like this: #!/usr/bin/env bash Bash3 Boilerplate. Copyright (c) 2014, kvz.ioset -o errexit set -o xtraceSet magic variables for current file & dir__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" arg1="${1:-}" |
|
http://yysfire.github.io/linux/sed-usage-summary.html
http://zhengheng.me/2015/11/12/sed-course/
http://coolshell.cn/articles/9104.html
http://sed.sourceforge.net/sed1line_zh-CN.html
http://man.linuxde.net/sed
http://wiki.jikexueyuan.com/project/shell-learning/sed-search-and-replace.html
http://coolshell.cn/articles/9104.html
The text was updated successfully, but these errors were encountered: