burim:bash
Table of Contents
Bash scripting cheatsheet
curl check website reachability
for i in $(seq 10); do echo "$i:"; curl --connect-timeout 1 -sLk https://ipinfo.io/ip -w "%{http_code}\n" -o /dev/null; done
cut
test command
Using test command
One can use the test command to check file types and compare values. For example, see if FILE exists and is a directory. The syntax is:
test -d "DIRECTORY" && echo "Found/Exists" || echo "Does not exist"
The test command is same as [ conditional expression. Hence, you can use the following syntax too:
[ -d "DIR" ] && echo "yes" || echo "noop"
Getting help Read bash shell man page by typing the following man command or visit online here:
man bash help [ help [[ man test
if statements
sunrise/sunset
http://www.giuseppeparrello.it/en/prg_bash_sunrise_sunset.php
https://linuxconfig.org/how-to-obtain-sunrise-sunset-time-for-any-location-from-linux-command-line
examples
cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l
Loop
samples loops
while 1 < 4; do nc -vz -w 1 google.de 443; done
for i in {1..1000}; do nc -vz -w 1 google.de 443 ; done
until [ 1 -ge 5 ]; do nc -vz -w 1 google.de 443 ; done
xargs opkg upgrade
opkg list-upgradable | cut -f 1 -d ' ' | xargs -r opkg upgrade
burim/bash.txt · Last modified: 2022/09/26 14:07 by burim
