How to assign variable to PROMPT_COMMAND

How can I increment a variable assigning its value to PROMPT_COMMAND variable?

Inside .bashrc I created variable a and assigned value to 0 and then added this

a=0
PROMPT_COMMAND=`((a++))`

When I echo PROMPT_COMMAND it shows that it is empty.

1

1 Answer

It works with

a=0
PROMPT_COMMAND='echo -n $((a++))'

after you open a new shell (or source .bashrc by calling . ~/.bashrc.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like