1

I need to have the following work:

$ read -r -p 'input: ' foo
input: <space><space><space>
$ echo "text""$foo""more text"
text   more text

Where <space><space><space> is replaced with actual spaces.

However this is only possible if I set the variable manually:

$ foo='   '
$ echo "text""$foo""more text"
text   more text

I thought using -r, aka raw, would not mess with input like this. How can I perform such a task?

Using bash 3.2.57(1)-release under El Capitan, but am willing to install 3rd party tools if needed.

leetbacoon
  • 1,111
  • 2
  • 9
  • 32
  • 1
    Though a good question, it is pretty much a duplicate of the linked one. Resetting the `IFS` should fix your problem. Do `IFS= read -r -p 'input: ' foo` – Inian Oct 07 '19 at 08:49
  • Additional info - http://mywiki.wooledge.org/BashFAQ/001#Trimming – Inian Oct 07 '19 at 09:02
  • Thanks @Inian, i admit was not easy to look since read is so common – leetbacoon Oct 07 '19 at 09:42

0 Answers0