LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2009, 01:48 AM   #1
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Rep: Reputation: 32
export filePath="/folder/folder with space/"


Exactly what the subject implies.
Ive tried escape characters, using quotes, using both...and everything I can see under the sun.
Literally spent 2 hours trying to figure this shit out...
 
Old 11-28-2009, 01:54 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
try
Code:
export filePath="folder/folder\ with\ space"
 
1 members found this post helpful.
Old 11-28-2009, 02:01 AM   #3
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Original Poster
Rep: Reputation: 32
nope
it says

cannot access /folder/folder\: No such file or directory
cannot access with\: No such file or directory
cannot access spaces/: No such file or directory
 
Old 11-28-2009, 02:07 AM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
What is the output from ls ?
does the dir exist ?
 
Old 11-28-2009, 02:24 AM   #5
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Original Poster
Rep: Reputation: 32
export thisVar = "/folder/folder\ with\ spaces/"
ls $thisVar
"/folder/folder\" does not exist
.....or
export thisVar = /folder/folder\ with\ spaces/
ls $thisVar
"/folder/folder" does not exist
.....or
export thisVar = "/folder/folder with spaces/"
ls $thisVar
"/folder/folder" does not exist
.......
none of the above methods recognize there is a space in the path

however:
ls /folder/folder\ with\ spaces/
works fine
 
Old 11-28-2009, 10:05 AM   #6
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
ls "$thisvar" would be recognized properly. Without the quotes around the variable, ls will interpret the expansion of the variable like any other space-separated list of words. i.e. the difference between
ls filename with spaces
and
ls "filename with spaces"
 
1 members found this post helpful.
Old 11-28-2009, 12:03 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
There are two separate issues at play here. The first is the one about which vendtagain asked, namely how to assign a text value containing space characters to an environment variable. This seems to have been adequately answered.
The second issue is how the application deals with those strings containing embedded whitespace. This would depend entirely on how the string is used, especially if it is being parsed in some way. Unless vendtagain has some control over this, it is likely that he has done all that can be done, with the exception of using filesystem names/paths that do no contain embedded whitespace.
It may be feasible to attach enclosing quotes of some sort, which the end application may understand to mean 'use everything between the quotes'. Likewise, it may be possible to embed escapes of some sort, which the end application interpets. Backslash characters are the conventional escape characters used in most situations.
--- rod.

Last edited by theNbomr; 11-28-2009 at 12:06 PM.
 
Old 11-28-2009, 02:37 PM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
It works for me:

Code:
bash-3.1$ export filePath="/folder/folder with space/"
bash-3.1$ echo $filePath
/folder/folder with space/
 
1 members found this post helpful.
Old 11-30-2009, 12:57 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
echo != ls


You can echo almost any string, certainly one with spaces, but ls and most *nix file handling tools eg mv, cp use whitespace as an arg separator ... unless you mess with IFS, but you'd need to know to do that every time.
That's why its very rare to see filenames with spaces in pure *nix systems.
They (the files) tend to have been imported from MS or created by an MS user.
 
Old 11-30-2009, 05:41 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
yes you can have any character in a filename bar
'/' and '\0'.

any character.

(try that on DOS)

though of course it is of limited utility.

 
1 members found this post helpful.
Old 11-30-2009, 07:11 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by chrism01 View Post
That's why its very rare to see filenames with spaces in pure *nix systems.
They (the files) tend to have been imported from MS or created by an MS user.
My system is rare (or maybe I'm a covert MS user at heart )!
Code:
c:~$ find . -name '* *' 2>/dev/null | wc -l
14476
Serimously, quotes allow whitespace in pathnames in (exported) variables
Code:
c:~$ export FOO='d/LQ reply snippets'
c:~$ ls -l "$FOO"
-rw-r--r-- 1 c 1000 993 Nov 27 11:56 d/LQ reply snippets
 
Old 11-30-2009, 07:45 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Yep, you can have spaces in filenames if you want, but as I said, you'd have to ensure every single program allows for that, and not just bash tools either.
By default, *nix tools take a space as the arg separator; it's not enforced but it is the convention.
As for *nix files usually not having spaces, I'm talking about those from the suppliers/repos. It's very rare, especially on non-Linux eg Solaris, HP-UX etc.

Last edited by chrism01; 12-07-2009 at 12:41 AM.
 
Old 12-04-2009, 03:03 PM   #13
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Actually, isn't it the shell that break arguments on whitespace? If I launch a program from a shell, it builds the argc/argv parameters from whatever is specified on the commandline, and passes those to the launched program. The same applies if any other program launches with exec() (in one of its many flavors), another program. The parent builds up the argc/argv parameters, of which any number of argvs may contain whitespace, and those arguments will remain intact when the child process accesses them. I do not know of a single common application that then splits individual arguments on whitespace in the character arrays. Can you name any?
Proper use of quotes and escapes in the shell is a key concept to be learned when shell scripting.
--- rod.
 
Old 12-04-2009, 03:19 PM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Why does the directory have spaces it its name in the first place?
 
Old 12-12-2009, 01:30 AM   #15
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Original Poster
Rep: Reputation: 32
Quote:
Why does the directory have spaces it its name in the first place?
I'm saving the files from a friends windows machine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a "fixed-space"-a folder that is EXT2 inside and whatever size-50MB? linus72 Linux - Newbie 3 04-08-2009 08:47 AM
Displaying "Subscribed Threads" -> new folder "All Folders" JZL240I-U LQ Suggestions & Feedback 5 06-15-2007 06:36 AM
How to issue "ls" command start with the largest file size in a folder? fjkum Linux - Newbie 5 07-27-2006 03:28 AM
"rm -rf /tmp", now Evolution shows "(no folder displayed" Ed-MtnBiker Linux - Software 7 04-10-2006 04:05 PM
"Mount" a folder into my ftp folder ? 0001001 Linux - General 3 11-27-2005 04:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration