Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
####### # # E-scripts on sh (a.k.a. dash) - a basic Unix shell. # # Note 1: use the eev command (defined in eev.el) and the # ee alias (in my .zshrc) to execute parts of this file. # Executing this file as a whole makes no sense. # An introduction to eev can be found here: # # (find-eev-quick-intro) # http://angg.twu.net/eev-intros/find-eev-quick-intro.html # # Note 2: be VERY careful and make sure you understand what # you're doing. # # Note 3: If you use a shell other than zsh things like |& # and the for loops may not work. # # Note 4: I always run as root. # # Note 5: some parts are too old and don't work anymore. Some # never worked. # # Note 6: the definitions for the find-xxxfile commands are on my # .emacs. # # Note 7: if you see a strange command check my .zshrc -- it may # be defined there as a function or an alias. # # Note 8: the sections without dates are always older than the # sections with dates. # # This file is at <http://angg.twu.net/e/sh.e> # or at <http://angg.twu.net/e/sh.e.html>. # See also <http://angg.twu.net/emacs.html>, # <http://angg.twu.net/.emacs[.html]>, # <http://angg.twu.net/.zshrc[.html]>, # <http://angg.twu.net/escripts.html>, # and <http://angg.twu.net/>. # ####### # «.simple-commands» (to "simple-commands") # «.parameter-expansion» (to "parameter-expansion") # «.default-values» (to "default-values") # «.important-commands» (to "important-commands") # «.functions» (to "functions") # «.for» (to "for") # «.case» (to "case") # «.showargs» (to "showargs") # «.test» (to "test") # «.redirection» (to "redirection") # «.multiline-comments» (to "multiline-comments") # «.PATH» (to "PATH") # «.shebang» (to "shebang") # «.shell-scripts-in-usr-bin» (to "shell-scripts-in-usr-bin") ##### # # Simple commands # 2019feb16 # ##### # «simple-commands» (to ".simple-commands") # (find-man "1 sh") # (find-man "1 sh" "generally executes") # (find-man "1 sh" " Commands\n") # (find-man "1 sh" " Simple Commands\n") # (find-man "1 sh" "first" "word" "command name") # (find-man "1 sh" "remaining words" "arguments") # (find-man "1 echo") # (find-man "1 sleep") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) echo a; echo b echo a; sleep 1; echo b; sleep 1; echo c; echo d echo a b c echo a b c echo echo sleep echo echo echo sleep echo sleep echo # (find-man "1 sh" " Double Quotes\n") echo echo sleep echo echo "echo sleep echo" ##### # # Parameter expansion # 2019feb16 # ##### # «parameter-expansion» (to ".parameter-expansion") # (find-man "1 sh" " Word Expansions\n") # (find-man "1 sh" " Parameter Expansion\n") # (find-man "1 sh" "${parameter}") # (find-man "1 sh" "braces" "optional") # (find-man "1 sh" " Double Quotes\n") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) A=foo B=bar AB=plic echo $A $B $AB $B $A echo $A$B$AB$B$A echo $A $B $AB $B $A echo "$A $B $AB $B $A" echo $A $B $AB $B $A echo "$A $B $AB $B $A" ##### # # default-values # 2019oct08 # ##### # «default-values» (to ".default-values") # (find-man "1 sh" "${parameter:-word}") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) export A=foo export B=bar echo ${A:-B} unset A echo ${A:-B} f () { echo ${1:-empty}; } f hello f f () { echo ${1:-$B}; } f hello f ##### # # important-commands # 2019sep04 # ##### # «important-commands» (to ".important-commands") # (find-fline "/bin/") # (find-fline "/usr/bin/") echo -h echo --help egrep --help false --help false -h fgconsole --help fgrep --help findmnt --help fuser --help # (find-man "echo") echo \a echo -n hello echo -e '\a' echo '\a' # (find-man "egrep") # (find-man "false") # (find-man "fgconsole") # (find-man "fgrep") # (find-man "findmnt") # (find-man "fuser") ##### # # functions # 2019feb17 # ##### # «functions» (to ".functions") # (find-man "1 sh" " Functions\n") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) f3 () { echo "1:($1) 2:($2) 3:($3)"; } f3 a b c f3 a b f3 a b c d f4 () { i=2; eval echo "\"$i:(\$$i)\""; } f4 () { for i in $(seq 1 $#); do eval echo "\"$i:(\$$i)\""; done; } f4 a b c d ##### # # for # 2019apr18 # ##### # «for» (to ".for") # (find-man "1 sh" "Flow-Control Constructs - if, while, for, case") # (find-man "1 sh" " The syntax of the for command is") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) seq 0 0 seq 0 4 for i in $(seq 0 4); do echo $i; done for i in ; do echo $i; done ##### # # case # 2022apr23 # ##### # «case» (to ".case") # (find-angggrep "grep --color=auto -nH --null -e case ~/bin/*") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) f () { case "_$1_" in _a_) echo A;; _bb_) echo B;; *) echo ETC;; esac } f a f bb f ccc f ##### # # showargs # 2019apr18 # ##### # «showargs» (to ".showargs") # (find-man "1 sh" " Special Parameters\n") # (find-man "1 sh" " Special Parameters\n" "#") # (find-man "1 sh" " Functions\n") # (find-man "1 sh" " Reserved Words\n") # (find-man "1 sh" "eval string ...") # (find-man "1 sh" "#" "number of positional parameters") showargs () { for i in $(seq 1 $#); do echo "$i: ($(eval echo \$$i))"; done } showargs () { for i in $(seq 1 $#); do eval echo "\"$i:(\$$i)\""; done } showargs a b c d showargs a b c " d " showargs a b showargs ##### # # test # 2021nov26 # ##### # «test» (to ".test") # (find-es "bash" "test") # (find-man "1 sh" "test expression") # (find-man "1 sh" "[ expression ]") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) if true; then echo yes; fi if false; then echo yes; fi if [ "" = "a" ]; then echo yes; fi if [ "a" = "a" ]; then echo yes; fi ##### # # redirection # 2019may17 # ##### # «redirection» (to ".redirection") # https://en.wikipedia.org/wiki/Pipeline_(Unix) # https://en.wikipedia.org/wiki/Terminal_emulator # https://en.wikipedia.org/wiki/Text_terminal # (find-man "1 sh" "Redirection operators:") # (find-man "1 sh" "[n]> file") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) * (eepitch-zsh) * (eepitch-kill) * (eepitch-zsh) f () { echo $1; sleep 2; echo $2; sleep 2; echo $3; } g () { sleep 1; f $*; } h () { f A B C & g a b c & } h f A B C & ; g a b c & * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) pwd cd /tmp/ pwd seq 3 20 seq 3 20 > /tmp/o cat /tmp/o grep 1 /tmp/o seq 3 20 | grep 1 ##### # # multiline-comments # 2019jun25 # ##### # «multiline-comments» (to ".multiline-comments") # https://stackoverflow.com/questions/43158140/way-to-create-multiline-comments-in-bash # https://stackoverflow.com/questions/43158140/way-to-create-multiline-comments-in-bash/#46049228 # http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#dot # (find-angg ".emacs" "ee-itest-sh") # (find-man "1 sh" " :") # (find-man "1 sh" " . file") * (eepitch-sh) * (eepitch-kill) * (eepitch-sh) : <<'%%%' HELLO %%% ##### # # PATH and which # 2019jun29 # ##### # «PATH» (to ".PATH") # (find-man "1 sh" "Path Search") # (find-node "(libc)Word Expansion") # (find-node "(libc)Standard Environment") # (find-node "(libc)Standard Environment" "PATH") # (find-node "(libc)Function Index" "execvp") # (find-node "(libc)Executing a File" "execvp") # https://unix.stackexchange.com/questions/311339/why-was-colon-chosen-as-path-separator ##### # # shebang # 2019sep17 # ##### # «shebang» (to ".shebang") # https://en.wikipedia.org/wiki/Shebang_(Unix) # https://en.wikipedia.org/wiki/Loader_(computing) ##### # # shell-scripts-in-usr-bin # 2019sep17 # ##### # «shell-scripts-in-usr-bin» (to ".shell-scripts-in-usr-bin") # (find-fline "/usr/bin/") # (find-man "1 file") # (find-man "1 file" "determine file type") # (find-man "1 grep") # (find-man "1 grep" "-i, --ignore-case") # (find-man "1 cut") # (find-man "1 cut" "-d, --delimiter=DELIM") # (find-man "1 cut" "-f, --fields=LIST") # (find-man "1 tee") * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) file /usr/bin/* file /usr/bin/* | grep -i 'shell script' # (find-fline "/usr/bin/") # (find-sh "file /usr/bin/*") # (find-sh "file /usr/bin/* | grep -i script") * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) file /usr/bin/* | grep -i 'shell script' | cut -d: -f1 file /usr/bin/* | grep -i 'shell script' | cut -d: -f1 | tee /tmp/o # (find-fline "/tmp/o") * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) seq 1 4 echo 1 2 3 4 for i in $(seq 1 4); do echo $i; done for i in $(echo 1 2 3 4); do echo $i; done echo a $(echo 1 2 3 4) b echo a $(echo 1 2 '3 ' 4) b echo "a $(echo 1 2 '3 ' 4) b" for i in $(echo 1 2 3 4); do echo $i; done for i in $(echo 1 2 3 4); do echo "($i)"; done for i in $(echo 1 2 '3 ' 4); do echo "($i)"; done for i in 1 2 '3 ' 4 ; do echo "($i)"; done for i in $(seq 1 5); do echo $i; sleep 1; done for i in $(seq 1 5); do echo $i; sleep 1; done & for i in $(seq 10 10 50); do echo $i; sleep 1; done & https://news.ycombinator.com/item?id=28231981 Unix shell programming: the next 50 years (acm.org) https://news.ycombinator.com/item?id=31830676 Effective Shell (effective-shell.com) https://blog.nullspace.io/batch.html https://news.ycombinator.com/item?id=35108822 Write Posix Shell (j3s.sh) - Emperor Sh *** https://news.ycombinator.com/item?id=35765707 Pure Sh Bible (github.com/dylanaraps) https://news.ycombinator.com/item?id=35985224 The Case for Bash (2021) (neversaw.us) - Kernighan and Pike *** https://blog.plover.com/Unix/whitespace.html # (find-sh "locate -i pike") # Local Variables: # coding: utf-8-unix # End: