bash - Comparison to exit status not working -


i'm trying customize bash prompt. want change color if enter command doesn't exist, or other reason fails. i'm new coding bash scripts, looked @ other scripts help, something's not working. here's code:

export prompt_command="     ps1='`         if [ $? -eq 0 ];             echo '                 \[\033[00;32m\]┌─\[\033[00;35m\]\u\[\033[01;32m\]@                 \[\033[00;35m\]\h\n\[\033[00;32m\]└─\[\033[01;32m\]                 (\[\033[01;35m\]\w\[\033[01;32m\])\[\033[00;32m\]\$';          else echo '                 \[\033[00;31m\]┌─\[\033[00;35m\]\u\[\033[01;31m\]@                 \[\033[00;35m\]\h\n\[\033[00;31m\]└─\[\033[01;31m\]                 (\[\033[35m\]\w\[\033[31m\])\[\033[00;31m\]\$';          fi`\[\033[0m\]'" 

i not have linebreaks in actual code, since messy ps1, added them make code easier read.

so, want compare exit status, $?, 0. reason variable $? doesn't change @ in script. remains 0, first condition true, when issue faulty command. i've tried adding echo $? code before if-case, , returns 0, if issuing echo $? command terminal returns different. i've tried copying working code mine, doesn't solve either. also, worked when used ' outer citation , " second. changed because script wouldn't accept ( character otherwise.

any ideas why , how can fix it?

the problem in code that quotation broken:

export prompt_command=" ps1='`     if [ $? -eq 0 ];         echo ' 

generally should work, try this:

ps1='`if [ $? -eq 0 ] ; echo y:; else echo n:; fi` 

here output after applying code:

 $ ps1='`if [ $? -eq 0 ] ; echo y:; else echo n:; fi`' y: y: y: y:false n: n: n:true y: y: 

note: pressing enter key, doesn't change prompt.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -