-
Notifications
You must be signed in to change notification settings - Fork 0
Unix commands
Tak Tran edited this page Jul 29, 2019
·
8 revisions
#!/bin/bash
set -euxo pipefail
https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
Only show errors (ie, send standard out to /dev/null)
[cmd] > /dev/nullOnly output (ie, send standard error to /dev/null)
[cmd] 2> /dev/nullxargs reads items from the standard input or pipes, delimited by blanks or newlines, and executes the command one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored.
https://neverendingsecurity.wordpress.com/2015/04/13/xargs-commands-cheatsheet/
Use -t to print the command being run (https://shapeshed.com/unix-xargs/)
echo 'one two three' | xargs -t rm
rm one two threeUse -L1 to trigger the command for every line
$ echo one\ntwo\nthree | xargs echo "pre"
pre one two three
$ echo one\ntwo\nthree | xargs -L1 echo "pre"
pre one
pre two
pre threeRead input from user
$ echo "$(read -p 'Tell me something? ' something; echo $something)"
Tell me something? hello
hello
Exits with error when non-zero
$ $(exit 0) || echo hello
$ $(exit 1) || echo hello
hello
Get headers
curl -I
Follow redirects
curl -L