From aa8663ed6df3160ff3eb559bf8a1c5ea389d0b6c Mon Sep 17 00:00:00 2001 From: I-Man Ng Date: Wed, 8 May 2019 22:51:00 +0800 Subject: [PATCH] Fix some bugs Thank you for StallmanTheLeft's correction! --- README.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 83de54d..8fb05fb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Here's a more stylish version of [Bash-Oneliner](http://onceupon.github.io/Bash- - [Awk](#awk) - [Xargs](#xargs) - [Find](#find) -- [Loops](#loops) +- [Condition and Loop](#condition-and-loop) - [Math](#math) - [Time](#time) - [Download](#download) @@ -888,7 +888,7 @@ find . -name "*.mso" -size -74c -delete ``` -## Loops +## Condition and loop [[back to top](#handy-bash-oneliner-commands)] ##### If statement @@ -929,7 +929,7 @@ if [ "$x" -ge 5 ]; then … if ((x >= 5)); then … # Use (( )) for arithmetic operation -if (($j==$u+2)) +if ((j==u+2)) # Use [[ ]] for comparison if [[$age >21]] @@ -941,12 +941,22 @@ if [[$age >21]] ```bash for i in $(ls); do echo file $i;done +#or +for i in *; do echo file $i; done # Press any key to continue each loop for i in $(cat tpc_stats_0925.log |grep failed|grep -o '\query\w\{1,2\}');do cat ${i}.log; read -rsp $'Press any key to continue...\n' -n1 key;done -# Print a file line by line when a key is pressed +# Print a file line by line when a key is pressed, +oifs="$IFS"; IFS=$'\n'; for line in $(cat myfile); do ...; done +while read -r line; do ...; done &1| tee logfile ``` +or + +```bash +some_commands |& tee logfile +``` or