diff --git a/docs/bash.md b/docs/bash.md index cd7c8bd..fa26ce5 100644 --- a/docs/bash.md +++ b/docs/bash.md @@ -4,7 +4,7 @@ Bash 备忘清单 这是开始使用 linux bash shell 脚本的快速参考备忘单。 入门 ---------------- +----- ### hello.sh @@ -837,7 +837,6 @@ if [[ "$1" == '--' ]]; then shift; fi ``` ### 检查命令的结果 - ```bash if ping -c 1 google.com; then @@ -845,6 +844,73 @@ if ping -c 1 google.com; then fi ``` +### grep 检查 + +```bash +if grep -q 'foo' ~/.bash_history; then + echo "您过去似乎输入过“foo”" +fi +``` + +### 写入文件 + + +:-- | -- +:-- | -- +`cat` | 用于显示文本文件内容,全部输出 +`EOF` | `end of file`,表示文本结束符 + +--- + +```bash +cat > output.txt <>2.txt < file < output.sh +echo "This is output" +echo $1 +EOF +``` + +所有TAB键将全部忽略[不能是空格] + +```bash +cat << -EOF + echo "This is output" +EOF +``` + ### 特殊变量 @@ -857,15 +923,6 @@ fi 见[特殊参数](http://wiki.bash-hackers.org/syntax/shellvars#special_parameters_and_shell_variables)。 -### grep 检查 - - -```bash -if grep -q 'foo' ~/.bash_history; then - echo "您过去似乎输入过“foo”" -fi -``` - ### 反斜杠转义