bash: expanding variables with spaces

Posted by adam n on Stack Overflow See other posts from Stack Overflow or by adam n
Published on 2010-03-30T06:51:07Z Indexed on 2010/03/30 6:53 UTC
Read the original article Hit count: 332

Filed under:
|
|
|
|

i have a file called physics 1b.sh
in bash, if i try

x="physics 1b"
grep "string" "$x".sh

grep complains:
grep: physics 1b: No such file or directory. However, when i do

grep "string" physics\ 1b.sh 

it works fine. So i guess the problem is something to do with the variable not being expanded to include the backslash that grep needs to recognize the space. How do i get this to work?

using bash 3.2, mac os 10.6.

© Stack Overflow or respective owner

Related posts about bash

Related posts about variable-expansion