mirror of
https://github.com/onceupon/Bash-Oneliner.git
synced 2024-11-25 22:07:01 +00:00
Fix some bugs
Thank you for StallmanTheLeft's correction!
This commit is contained in:
parent
19dc622b02
commit
aa8663ed6d
27
README.md
27
README.md
@ -17,7 +17,7 @@ Here's a more stylish version of [Bash-Oneliner](http://onceupon.github.io/Bash-
|
|||||||
- [Awk](#awk)
|
- [Awk](#awk)
|
||||||
- [Xargs](#xargs)
|
- [Xargs](#xargs)
|
||||||
- [Find](#find)
|
- [Find](#find)
|
||||||
- [Loops](#loops)
|
- [Condition and Loop](#condition-and-loop)
|
||||||
- [Math](#math)
|
- [Math](#math)
|
||||||
- [Time](#time)
|
- [Time](#time)
|
||||||
- [Download](#download)
|
- [Download](#download)
|
||||||
@ -888,7 +888,7 @@ find . -name "*.mso" -size -74c -delete
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Loops
|
## Condition and loop
|
||||||
[[back to top](#handy-bash-oneliner-commands)]
|
[[back to top](#handy-bash-oneliner-commands)]
|
||||||
|
|
||||||
##### If statement
|
##### If statement
|
||||||
@ -929,7 +929,7 @@ if [ "$x" -ge 5 ]; then …
|
|||||||
if ((x >= 5)); then …
|
if ((x >= 5)); then …
|
||||||
|
|
||||||
# Use (( )) for arithmetic operation
|
# Use (( )) for arithmetic operation
|
||||||
if (($j==$u+2))
|
if ((j==u+2))
|
||||||
|
|
||||||
# Use [[ ]] for comparison
|
# Use [[ ]] for comparison
|
||||||
if [[$age >21]]
|
if [[$age >21]]
|
||||||
@ -941,12 +941,22 @@ if [[$age >21]]
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
for i in $(ls); do echo file $i;done
|
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
|
# 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
|
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 <myfile
|
||||||
|
|
||||||
|
#If only one word a line, simply
|
||||||
for line in $(cat myfile); do echo $line; read -n1; done
|
for line in $(cat myfile); do echo $line; read -n1; done
|
||||||
|
|
||||||
|
#Loop through an array
|
||||||
|
for i in "${arrayName[@]}"; do echo $i;done
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
##### While loop,
|
##### While loop,
|
||||||
@ -1035,6 +1045,8 @@ echo ${var,,}
|
|||||||
helloworld
|
helloworld
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Math
|
## Math
|
||||||
[[back to top](#handy-bash-oneliner-commands)]
|
[[back to top](#handy-bash-oneliner-commands)]
|
||||||
##### Print out the prime factors of a number (e.g. 50)
|
##### Print out the prime factors of a number (e.g. 50)
|
||||||
@ -1581,7 +1593,7 @@ id username
|
|||||||
##### Check if it's root
|
##### Check if it's root
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
if [$(id -u) -ne 0];then
|
if [ $(id -u) -ne 0 ];then
|
||||||
echo "You are not root!"
|
echo "You are not root!"
|
||||||
exit;
|
exit;
|
||||||
fi
|
fi
|
||||||
@ -2185,6 +2197,11 @@ or
|
|||||||
```bash
|
```bash
|
||||||
some_commands 2>&1| tee logfile
|
some_commands 2>&1| tee logfile
|
||||||
```
|
```
|
||||||
|
or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
some_commands |& tee logfile
|
||||||
|
```
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user