I'm trying to make function-wrapper for another functions to distinguish its in terminal
red_line="$(tput setaf 1)## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## $(tput sgr 0)"
function wrapper {
echo $red_line;
echo "$(tput setaf 1)## $(tput setab 7)$(tput setaf 0)$1 $(tput sgr 0)";
$2;
echo $red_line;
}
function foo {
wrapper "custom command description" "ps axo pid,stat,pcpu,comm | tail -n 10;"
}
but error was occurred: ps: illegal argument: |
I've tried to use $(ps ... | tail -n 10) and backticks instead of string and then print out result in wrapper with echo $2, but caught another errors
Also tried "eval $(ps ... | tail -n 10)" and it also didn't work.
Everything works just fine w/o wrapper:
function pss {
echo $red_line
echo "$(tput setaf 1)## $(tput setab 7)$(tput setaf 0)formatted 'ps ax' command $(tput sgr 0)"
ps axo pid,stat,pcpu,comm | tail -n $1;
echo $red_line
}