You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# chmod +rx scriptnameecho"Here"# A whitespace before '#' in commentecho -n $var# echo variable without newline character
hello="A B C D"echo$hello# A B C D (variable reference)echo"$hello"# A B C D (variable itself)if [ -n"${10}" ] # Parameters > $9 must be enclosed in {brackets}.
arch=$(uname -m)# get current OS's archif [ !-f"$filename" ] # Quoting $filename allows for possible spaces.
find ~/ -name 'core*' -exec rm {} \;# Removes all core dump files from user's home directory.
Ctrl-H
Erases characters back
Bash sets the “integer value” of a string to 0.
$# : number of parameters
$*/$@ : all the positional parameters. P778
P53 : get keyboard input
1.2 Redirect
1>filename
# Redirect stdout to file "filename."1>>filename
# Redirect and append stdout to file "filename."2>filename
# Redirect stderr to file "filename."2>>filename
# Redirect and append stderr to file "filename."&>filename
# Redirect both stdout and stderr to file "filename."# This operator is now functional, as of Bash 4, final release.
M>N
# "M" is a file descriptor, which defaults to 1, if not explicitly set.# "N" is a filename.# File descriptor "M" is redirect to file "N."
M>&N
# "M" is a file descriptor, which defaults to 1, if not set.# "N" is another file descriptor.# 2>&1 ==> Redirects stderr to stdout. >&j
# Redirects, by default, file descriptor 1 (stdout) to j. # All stdout gets sent to file pointed to by j.
2 Useful Tips
space do matters
Sed almost always runs faster than awk
tree ignore by pattern link
$tree -I ‘node_module*’ to ignore node_modules/
mess stuff
cat {file1,file2,file3} > combined_file
# Concatenates the files file1, file2, and file3 into combined_file.
cp file22.{txt,backup}
# Copies "file22.txt" to "file22.backup"
(cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xpvf -)
# Move entire file tree from one directory to another # abs-guide P28echo`date`| pbcopy
# get date string into clipboard read -p "Want to start? (y/n) " res
if [ "$res"="y"];then# do blah blahelse# do blah blahfi