1

I'm trying to do the following:

ch='\x21'
line="\x21"
len=50
for i in `seq 1 $len`
do
    line+="$ch"
done

Instead of 50 '!' (hex code \x21) I get a list of 50 '\x21'. How can I do this in bash?

  • Do you want the total sum of it? – Kira Nov 5 '15 at 19:39
1

Per the man page, "Words of the form $'string' are treated specially". Thus, adding $'' to the mix may help:

% bash
bash-3.2$ ch=$'\x21'; echo $ch$ch$ch
!!!
bash-3.2$ 

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.