View Full Version : Bash filenames with spaces
kerryhall
August 19th, 2011, 11:33 PM
I searched for similar issues but everything I could find was a different case than mine.
I want to assign a path with spaces to a variable in Bash like so
$FILENAME="/path/to/file\ with\ spaces"
but it doesn't seem to work. Any ideas? Thanks!!
sisco311
August 19th, 2011, 11:43 PM
I rarely have to say this, but you use too many quotes. :)
FILENAME="/path/to/file with spaces"
FILENAME='/path/to/file with spaces'
FILENAME=/path/to/file\ with\ spaces
Check out:
man bash | less +/^QUOTING
EDIT: and http://mywiki.wooledge.org/Quotes
Smart Viking
August 19th, 2011, 11:44 PM
You assign without the dollar:
FILENAME="/path/to/file\ with\ spaces"
echo $FILENAME
ofnuts
August 20th, 2011, 01:02 AM
And don't forget to use "$FILENAME" about everywhere else...
Habitual
August 22nd, 2011, 03:01 AM
Check out:
man bash | less +/^QUOTING
is SEXY!
Thanks!
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.