Someone shared these handy functions with us a couple of years back

function third(){ awk '{if (NR%3==0){print "\033[32m" $0 "\033[0m"} else{print}}'; }

every third line looks nice

#bash #sh #zsh #ksh #csh #100DaysOfCode #Linux #POSIX #advancedProgramming

function psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto; }

greps your processes and shows them in a nice manner (as a tree)

#bash #sh #zsh #ksh #csh #100DaysOfCode #Linux #POSIX #advancedProgramming

@RadioAzureus nice! Why not pgrep?

@alan

The wonderfull thing about functions is that you can alias them as you feel fit. so you may use 'pgrep' as the function name for yourself

@RadioAzureus yep, but I think the built-in command pgrep does more or less the same thing as your psgrep function.

@alan I just checked out pgrep, the default output does not give anything else but the process numbers

That means you need to add switches to get something similar to what the PSgrep function does

function mkcd(){ [ ! -z "$1" ] && mkdir -p "$1" && cd "$_"; }

does a mkdir / cd dir for you

#bash #sh #zsh #ksh #csh #100DaysOfCode #Linux #POSIX #advancedProgramming

@RadioAzureus

I like that, but I think [ "$1" ] or [ -n "$1" ] or especially [[ $1 ]] is a bit more elegant.

Also, for better cross-shell scripting (especially ksh), pick either `function foo {` or `foo() {`, but not both (`function foo() {`) -- while it's my preferred form, it doesn't work in ksh, and I had to go fixing it on my scripts when I wanted to run them on BSD without installing bash (because the two languages are similar)

@RL_Dane

Thank you for that valuable feedback

@RL_Dane @RadioAzureus Does BSD have Perl by default? At least I changed some parts to Perl for fish and bash compatibility, and it works fine.

I use 'lolcat' instead of third function described above because I love ❤️ lolcat output colours

However that is not everyone's cup of tea

#bash #sh #zsh #ksh #csh #100DaysOfCode #Linux #POSIX #advancedProgramming