Ash Escaping Complex Quotes

Hello,
Should be an easy one, but I am trying to get the following command line:-

/usr/bin/hexdump -n1 -e'1/1 "%u"'

Into a single script variable, so that I can use it multiple times.
I have tried:-

#!/bin/sh
HD="/usr/bin/hexdump -n1 -e'1/1 \"%u\"'"
echo $($HD /dev/urandom)

But this keeps reporting the error "hexdump: bad format {'1/1}".
Searching on this forum, I found a suggestion to add -vx to the interpreter command, which shows it's adding extra single quotes around both halves of the format string (the bit after -e).

Is there a way to fix this? I've tried several permutations of escaped quotes and am getting nowhere :face_with_spiral_eyes:

Make it a function:

$ HD() { /usr/bin/hexdump -n1 -e'1/1 "%u"' $1; }

$ HD /dev/urandom
94
1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.