Skip to content

Latest commit

 

History

History
96 lines (67 loc) · 3.01 KB

File metadata and controls

96 lines (67 loc) · 3.01 KB

Hello POSIX

Short for Portable Operating System Interface (the X apparently has no meaning), POSIX is a set of standards for tools to work across operating systems, like how Bash works nearly the same in Windows and Linux distributions.

POSIX also defines the Shell Command Language and many utilities like cd. Bash aims to be compliant with POSIX.

Utilities

grep

grep -- search a file for a pattern

# Search this monorepo for "auth.md", succeeding even if nothing is found
grep -RIn --exclude-dir=node_modules -- "auth.md" ./path/to/hello-hello || true

mv

mv -- move files

Doesn't seem to take fancy args on its own, need to learn more about piping and xargs to get good use out of this.

sed

sed -- stream editor

MY_FILE="./src/pages/blog/content/__todo__"
sed -i "s/’/'/g" $MY_FILE
sed -i 's/[“”]/"/g' $MY_FILE
sed -i 's/…/.../g' $MY_FILE

Shell Command Language

Links are to official sources unless otherwise specified. Citations in code use the same numbering and name as in official sources.

Shell Command Language

Full name: Volume: XCU, Chapter 2: Shell Command Language

Redirecting output

2.7.2 Redirecting output

# Print stdout to a file
# 2.7.2 Redirecting output
echo Hello > out.log
# Print stdout and stderr to the same file
# 2.7.6 Duplicating an Output File Descriptor
echo Hello > out.log 2>&1

Pipelines

2.9.2 Pipelines

echo "Hello
world" | grep Hello

For loop

2.9.4.2 The for loop

for name [ in [word ... ]]
do
    compound-list
done
for i in {1..3}; do echo Hello; done