This shows you the differences between two versions of the page.
|
bash [2018/02/11 15:38] |
bash [2025/04/04 10:05] (current) rzr [LINKS] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== LEARN ===== | ||
| + | |||
| + | * https://devhints.io/bash | ||
| + | * https://github.com/dylanaraps/pure-bash-bible | ||
| + | * https://news.ycombinator.com/item?id=25428621# MinimaL | ||
| + | * https://betterprogramming.pub/24-bashism-to-avoid-for-posix-compliant-shell-scripts-8e7c09e0f49a# | ||
| + | * https://bobcopeland.com/blog/2012/10/goto-in-bash/ | ||
| + | |||
| + | ==== OneLiner ==== | ||
| + | |||
| + | * https://github.com/onceupon/Bash-Oneliner | ||
| + | * https://ocv.me/doc/unix/oneliners/ | ||
| + | |||
| + | for i in {0..65535} ; do printf "%x\n" $i ; done \ | ||
| + | | while read -r hex ; do printf "$hex(%d): \U$hex\n" 0x$hex ; done | ||
| + | |||
| + | |||
| + | ==== arrays === | ||
| + | |||
| + | <code> | ||
| + | list=( | ||
| + | "item" | ||
| + | "item with space" | ||
| + | ) | ||
| + | |||
| + | for item in "${list[@]}" ; do | ||
| + | echo "$item" | ||
| + | done | ||
| + | </code> | ||
| + | |||
| + | echo 1 2 3 | { read -a words ; for value in "${words[@]}" ; do echo $value ; done } | ||
| + | |||
| + | end_date=($(date --date "$(date +%Y-%m-01) -1 day" "+%d %m %y")) | ||
| + | start_date=(${end_date[*]}) | ||
| + | start_date[0]="01" | ||
| + | |||
| + | echo ${start_date} # 01 | ||
| + | echo "${#start_date}" # 2 | ||
| + | |||
| + | echo ${start_date[*]} # 01 04 20 | ||
| + | echo "${#start_date[*]}" # 3 | ||
| + | |||
| + | echo ${end_date[*]} # 30 04 20 | ||
| + | echo "${start_date[@]:0:2}" # 01 04 | ||
| + | |||
| + | |||
| + | |||
| + | * http://wiki.bash-hackers.org/syntax/arrays | ||
| + | * https://www.gnu.org/software/bash/manual/html_node/Arrays.html | ||
| + | |||
| + | @TaG: ArraY | ||
| + | |||
| + | |||
| + | ==== bug ? ==== | ||
| + | |||
| + | <code> | ||
| + | $SHELL --version && export LANG=C ; for i in $(seq 1 20) ; do printf "[%d]\n" 0$i ; done 2>&1 | grep ": invalid" | ||
| + | GNU bash, version 3.2.48(1)-release (i486-pc-linux-gnu) | ||
| + | Copyright (C) 2007 Free Software Foundation, Inc. | ||
| + | bash: printf: 08: invalid number | ||
| + | bash: printf: 09: invalid number | ||
| + | bash: printf: 018: invalid number | ||
| + | bash: printf: 019: invalid number | ||
| + | |||
| + | $SHELL --version && export LANG=C ; for i in $(seq 1 20) ; do printf "[%d]\n" 0$i ; done 2>&1 | grep ": invalid" | ||
| + | GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) | ||
| + | Copyright (C) 2013 Free Software Foundation, Inc. | ||
| + | License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> | ||
| + | |||
| + | This is free software; you are free to change and redistribute it. | ||
| + | There is NO WARRANTY, to the extent permitted by law. | ||
| + | bash: printf: 08: invalid octal number | ||
| + | bash: printf: 09: invalid octal number | ||
| + | bash: printf: 018: invalid octal number | ||
| + | bash: printf: 019: invalid octal number | ||
| + | |||
| + | |||
| + | </code> | ||
| + | |||
| + | Fixed in : | ||
| + | GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu) | ||
| + | |||
| + | |||
| + | GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu) | ||
| + | |||
| + | bash: printf: 08: invalid octal number | ||
| + | bash: printf: 09: invalid octal number | ||
| + | |||
| + | printf "[%04d]\n" 9 | ||
| + | [0009] | ||
| + | |||
| + | @TaG: PrintF | ||
| + | |||
| + | ==== fork bomb ==== | ||
| + | |||
| + | :(){:|:&};: # fork bomb | ||
| + | |||
| + | url=http://view.atdmt.com/action/dlXP ; while [ true ] ;do wget -O /dev/null $url ; sleep 1 ; done | ||
| + | |||
| + | |||
| + | |||
| + | ==== ${#foo} ==== | ||
| + | |||
| + | <code> | ||
| + | display_string_by_packet() | ||
| + | { | ||
| + | res_string="" | ||
| + | packet_len=1 | ||
| + | [ "_" != "_${2}" ] && packet_len=$2 | ||
| + | if [ 0 -lt ${packet_len} ] ; then | ||
| + | src_string=${1} | ||
| + | pos=${#src_string} | ||
| + | len=${packet_len} | ||
| + | while [ 0 -lt ${pos} ] ; do | ||
| + | pos=$((pos-${packet_len})) | ||
| + | if [ 0 -ge ${pos} ] ; then | ||
| + | len=$((${packet_len}+${pos})) | ||
| + | pos=0 | ||
| + | fi | ||
| + | res_string=${src_string:${pos}:${len}}" "${res_string} | ||
| + | done | ||
| + | fi | ||
| + | echo -n ${res_string} | ||
| + | } | ||
| + | |||
| + | |||
| + | display_string_by_packet "this is a test" 2 | ||
| + | #| th is i s a te st | ||
| + | |||
| + | </code> | ||
| + | |||
| + | |||
| + | ==== variables ==== | ||
| + | |||
| + | echo ${foo:-bar} | ||
| + | bar | ||
| + | |||
| + | === $@ === | ||
| + | |||
| + | echo $@ | sort | while read t ; do cat "$t" ; done > "${file}" | ||
| + | |||
| + | https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html#index-_0040 | ||
| + | ==== getopts ==== | ||
| + | |||
| + | * https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html | ||
| + | * https://wiki-dev.bash-hackers.org/howto/getopts_tutorial# | ||
| + | |||
| + | |||
| + | ==== ops ==== | ||
| + | |||
| + | * https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Here-Documents <<< | ||
| + | ===== env ===== | ||
| + | |||
| + | <code> | ||
| + | # rzr@lap:tmp/ # [126] # mkdir /tmp/bin/; touch /tmp/bin/script.sh | ||
| + | # rzr@lap:tmp/ # [0] # PATH="/tmp/bin:$PATH" which script.sh | ||
| + | # rzr@lap:tmp/ # [1] # PATH="/tmp/bin:$PATH" script.sh | ||
| + | bash: /tmp/bin/script.sh: Permission denied | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ===== MISC ===== | ||
| + | |||
| + | * http://wiki.bash-hackers.org/snipplets/start | ||
| + | * https://github.com/vlisivka/bash-modules | ||
| + | |||
| + | Interactive Shell | ||
| + | |||
| + | if [ "${-#*i}" != "$-" ]; then | ||
| + | |||
| + | * http://www.tldp.org/LDP/abs/html/intandnonint.html#IITEST | ||
| + | * http://mywiki.wooledge.org/BashFAQ/002?action=diff&rev2=35&rev1=33 | ||
| + | * https://github.com/tdenniston/bish# TooL CompilE | ||
| + | * https://n0where.net/bash-open-tcpudp-sockets# SockeT | ||
| + | * https://github.com/aristocratos/bashtop# CurseS | ||
| + | * https://github.com/petobens/trueline# | ||
| + | * https://betterdev.blog/minimal-safe-bash-script-template/# | ||
| + | |||
| + | |||
| + | ===== LINKS ===== | ||
| + | |||
| + | * https://github.com/oils-for-unix/oils/wiki/The-Biggest-Shell-Programs-in-the-World | ||
| + | * https://github.com/lsferreira42/bash-ini-parser# ParseR | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ===== MORE ===== | ||
| + | |||
| + | @TaG: [[Shell]] [[sh]] [[printf]] DeclarE | ||
| + | |||
| + | {{http://www.monsterbashnews.com/bash/Bash2006lobbyzach.jpg}} | ||