Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Is there any way to read raw text from stdin before it is expanded or before the shell does anything to it? Say I wanted to run a script where a user enters a string which is then printed out, how can I get the following behavior:

$ sh
Please enter a string:

You entered:

Is there any way to implicitly surround the text with '' or escape all meta characters even if the user does not?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Try doing this :

$ read -r -p 'Please enter a string >>> ' var
$ printf '%q\n' "$var"
share|improve this answer
Thanks, +1 as soon as I get to 15 reputation! – gambol Feb 25 '13 at 2:25
The -r is the magic option; see help read. – l0b0 Feb 25 '13 at 16:30
No, the magic is %q – Gilles Quenot Feb 27 '13 at 16:28

Your Answer


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.