I would like to query and store the current terminal color pair in BASH e.g.:
#!/bin/bash
#some ANSI colour escape sequences
red=\"\\033[0;31m\"
grn=\"\\033[0;3
You can't; there is no standard control sequence to report the current cursor attributes.
What does exist, however, is a sequence to save and restore the current cursor position and attributes:
\e7
(DECSC) will save the cursor position and attributes.\e8
(DECRC) will restore the saved cursor position and attributes.There is no standard way to restore only the cursor attributes; however, as rici mentioned, you can get a report of the current position using \e[6n
(DSR), then use the response to manually "un-restore" the cursor position after restoring its position and attributes.
Again, though, it's probably easier (and better) to just keep track of the colors in your application, rather than making the terminal responsible for that.