Skip to content

Instantly share code, notes, and snippets.

View zsxwing's full-sized avatar
:octocat:

Shixiong Zhu zsxwing

:octocat:
  • Databricks, Inc.
  • San Francisco
View GitHub Profile
@zsxwing
zsxwing / comment.sh
Created April 7, 2013 12:22
How to use comments in shell.
# one line comment
:<<test
Multiple lines comment.
test
@zsxwing
zsxwing / usage.sh
Last active December 15, 2015 21:58
Convenient way to write a usage function.
usage() {
cat <<END;
ez_mail TITLE CONTENT FROM_ADDRESS RECIEVER_ADDRESS
EXAMPLE
ez_mail 'Hello World!' 'Hi!' example@example.com somebody@example.com
END
}
@zsxwing
zsxwing / error_log.sh
Last active December 15, 2015 21:58
A error function to output the message with time.
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
@zsxwing
zsxwing / long_string.sh
Last active December 15, 2015 21:58
How to create a long string in bash shell
# output "I am an exceptionally long string."
long_string="I am an exceptionally
long string."
echo ${long_string}
@zsxwing
zsxwing / iter_lines.sh
Last active December 15, 2015 21:58
How to iterate lines in a file or generated by a command correctly.
while read line; do
echo $line;
done < <(cat test.txt)
@zsxwing
zsxwing / argument.sh
Last active December 15, 2015 21:58
Set the $1 $2 $3, ..., and $# in the current terminal. Avoid to open a new file when you just want to test a small function.
set -- a b c
echo "$1 $2 $3"