so ... [[ $- != *i* ]] && return actually does what it says above in a comment: it checks if the interactive flag is set. The [[ and ]] make it a boolean so it ends up in a "true" or "false". "false && return" makes it go on "true && return" makes it execute the return.
The default flags explained in more detail:
h is for "hash all": this tells bash to remember the locations of commands it has found through querying your PATH.
i is for "interactive": entering input & getting back output.
m is for "monitor": this enables job control
B is for "brace expand". This allows you to use brace expansion
H is for "history expand". This is what enables you to rerun a command from your history by prefacing its number with an exclamation point
By the way. I have ...
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
Basically does the same but easier to read I assume.
Best Answer
The
>
operator redirects the output usually to a file but it can be to a device. You can also use>>
to append.If you don't specify a number then the standard output stream is assumed, but you can also redirect errors:
> file
redirects stdout to file1> file
redirects stdout to file2> file
redirects stderr to file&> file
redirects stdout and stderr to file> file 2>&1
redirects stdout and stderr to file/dev/null
is the null device it takes any input you want and throws it away. It can be used to suppress any output.Note that
> file 2>&1
is an older syntax which still works,&> file
is neater, but would not have worked on older systems.