Output redirect to variable with blanks

0

I'm doing a script where I want to capture a path to the name of a user's file and then use it, plus the extension, to redirect the output of a command.

example: Insert path: ~/Videos/file

I do this using " read -e path ", and then redirecting the output like this: foo > ${path}.abc

But if this path has spaces, for example, ~/Área\ de\ Trabalho , it goes wrong.

How to capture the path so that it works even for those with blanks?

Thank you in advance.

    
asked by anonymous 06.09.2015 / 22:09

1 answer

0

Try something like

foo >  "${path/\~/$HOME}.abc"

Where

  • apspas protect spaces
  • ${var/pat/sub} replaces pattern "pat" with value "sub" in $var
10.09.2015 / 12:22