Article 5JA68 bash command or function that doesn't change the error code

bash command or function that doesn't change the error code

by
PeterPanic
from LinuxQuestions.org on (#5JA68)
Hi!

I'm trying to write a bash function or command that will not alter the error level of the previous command.

My application: I wat to create a $PS1 that outputs the error level of the last command (green=OK=0, red=error!=0) in my prompt ($PS1) within a function or script that returns the stdout colored string, I can never manage to KEEP the error level as it was....

As soon as I create a bash function or command that sets the color to grreen/red (echo/printf), they always return "0" as their error level.

Even if I try things like that as "color.sh:
Code:#!/bin/bash
errorLevel=$?
case "$1" in
"black") printf '\e[30m' ;;
"d-red") printf '\e[31m' ;;
"d-green") printf '\e[32m' ;;
"brown") printf '\e[33m' ;;
"d-blue") printf '\e[34m' ;;
"magenta") printf '\e[35m' ;;
"cyan") printf '\e[36m' ;;
"l-gray") printf '\e[37m' ;;
"d-gray") printf '\e[90m' ;;
"red") printf '\e[91m' ;;
"green") printf '\e[92m' ;;
"yellow") printf '\e[93m' ;;
"blue") printf '\e[94m' ;;
"pink") printf '\e[95m' ;;
"sky") printf '\e[96m' ;;
"white") printf '\e[97m' ;;
*) printf '\e[m' ;;
esac
exit $errorLevelAfterwards, the error level will always be "0" ... :(

How can I write a function or command that does not change the error level ($?)?latest?d=yIl2AUoC8zA latest?i=Y_FeBROQoR4:muArBtW2cpk:F7zBnMy latest?i=Y_FeBROQoR4:muArBtW2cpk:V_sGLiP latest?d=qj6IDK7rITs latest?i=Y_FeBROQoR4:muArBtW2cpk:gIN9vFwY_FeBROQoR4
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments