How to see hidden characters.....

I know that cat -v will show me hidden characters in a file....

I for some reason seem to think that there's a bash command that will show me hidden characters in a variable in a script? Or am I just imagining it?

Thanks in advance

Interesting. I have never come across such a Bash builtin.

You could construct something - try this:

echo "$variable" | tr -dc '[:print:]' | od -c
echo $variable | cat -v

jlliagre's answer is the best choice, but the OP does not want cat -v, I thought.

It's unclear if the OP doesn't want "cat -v" or simply think "cat -v" is restricted to files and something different should be used for variables.

Using a bash shell cat -v only seems to work on files, the example given above with echo $variable | cat -v doesn't produce any output.

Not true, though I would prefer:

echo "${variable}" | cat -v

It certainly does, or at least should.

$ cat -v /tmp/t
bell^G
$ od -c /tmp/t
0000000   b   e   l   l 007  \n
0000006
$ variable=$(</tmp/t)
$ echo $variable | cat -v
bell^G
$

Please provide some clues about your tests.