2023-02-17 · 4분
Vim
A quick Vim reference: what Vim is and why it beats plain shortcuts, NORMAL/INSERT modes, navigation and editing commands, plus the Command + Object grammar (d3w, dit, daw) for advanced use.
2022-02-11 · 3분
This post is over 2 years old. The content may be outdated.
- chmod 700(755) [a.sh](http://a.sh) → ./a.sh
Numeric comparison / description / string comparison / description / file comparison / description
<table style="border-collapse: collapse; width: 100%;" border="1" data-ke-align="alignLeft"><tbody><tr><td>A -eq B</td><td>Is A equal to B</td><td>A = B</td><td>Are strings A, B equal</td><td>-d file</td><td>Does the file exist and is it a directory</td></tr><tr><td>A -ge B</td><td>Is A greater than or equal to B</td><td>A != B</td><td>Are strings A, B different</td><td>-e file</td><td>Does the file exist</td></tr><tr><td>A -gt B</td><td>Is A greater than B</td><td>A < B</td><td>Is string A less than B (by byte)</td><td>-f file</td><td>Does the file exist and is it a file</td></tr><tr><td>A -le B</td><td>Is A less than or equal to B</td><td>A > B</td><td>Is string A greater than B (by byte)</td><td>-r file</td><td>Does the file exist and is it readable</td></tr><tr><td>A -lt B</td><td>Is A less than B</td><td>-n A</td><td>Is A's string length greater than 0</td><td>-s file</td><td>Does the file exist and is it non-empty</td></tr><tr><td>A -ne B</td><td>Are A and B not equal</td><td>-z A</td><td>Is A's string length 0</td><td>-w file</td><td>Does the file exist and is it writable</td></tr></tbody></table>
case variable in
pattern1)
command to run if pattern1 matches;;
pattern2)
command to run if pattern2 matches;;
*)
command to run if none of the patterns above match;;
esac
for variable in data-to-iterate
do
command to run repeatedly until the data ends
done
while condition
do
command to run repeatedly while the condition is true
done
#!/bin/bash
for SVR in 22.1.24.10 22.1.24.20 22.1.24.30
do
echo "This is ${SVR} Server"
ssh ${SVR} "hostname"
done
for NUM in $(seq 1 3)
do
echo "Printing [${NUM}]"
echo ""
done
#!/bin/bash
./nginx.sh start
./nginx.sh restart
./nginx.sh stop
CMD=$1
case "$CMD" in
start)
systemctl start nginx;;
restart)
systemctl restart nginx;;
stop)
systemctl stop nginx;;
status)
systemctl status nginx;;
*)
echo "wrong code";;
esac
Example 1: output a message if the load is 5 or more
Example 2: output nginx's process number, then shut down the system
Example 3: after finding out the hostname, determine whether it's a kerberos server
Example 4: change network adapter settings
Try making the opposite case too
Original (Korean): tistory — published 2022-02-11, migrated to this blog. This translation was generated with the help of AI.
…