Take the 2-minute tour ×
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.

How can i give space " " as input in shell script ?

Ex :

echo " Enter date for grep... Ex: Oct  6 [***Double space is important for single date***] (or) Oct 12 "
read mdate 
echo $mdate

In this i get output as "Oct 6" But i want "Oct  6"

How can i do it ?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

You already have Oct  6 in $mdate, your problem is that you're expanding it when printing. Always use double quotes around variable substitutions:

read -r mdate
echo "$mdate"

The -r (raw) option to read tells it not to treat backslashes specially, which is what you want most of the time (but it's not the problem here).

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.