Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to echo out a string in tcsh such that it is fully escaped, as tcsh would understand? In the same way as printf %q works in bash:

% # Create a variable containing a tab character
% MYMONKEY=$'my\tmonkey'
% printf %q "$MYMONKEY"
$'my\tmonkey'

Which can then be used to re-input the variable into bash. Anyone know of anything similar in tcsh?

share|improve this question
    
I've usually had to write a filter program (sed script) for just such a purpose. –  mdpc Feb 13 '13 at 17:53

1 Answer 1

Workaround idea:

in tcsh

set MYMONKEY="my\tmonkey"

Note you do not add a "\n" at the end so the output will reflect this decision:

 printf "%s" $MYMONKEY
 my\tmonkey_My_Login_Name_@myhost>

 to fix it you can use 

 printf "%s\n" $MYMONKEY
 my\tmonkey
 _My_Login_Name_@myhost>

or

 printf $MYMONKEY
 my      monkey_My_Login_Name_@myhost>_

 echo $MYMONKEY
 my      monkey
 _My_Login_Name_@myhost>_
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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