LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 03-07-2006, 02:40 AM   #1
s_deepak_123
Member
 
Registered: Oct 2004
Location: Mysore, India
Distribution: Fedora Core 1, Xandros desktop OS 2
Posts: 54

Rep: Reputation: 15
How to access directory names that contain spaces ?


Hi all,

I have a script, that is supposed to search for files in all directories. Here is the part of it

for filename in `ls` ; do
cd "$filename"
# Searching files
done

Above code will work fine for all directories that doesn't contain any spaces in their names. But when a directory that contains space in its name, can't be accessed as the name gets split.

Thanks in advance.
 
Old 03-07-2006, 03:07 AM   #2
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Quote:
for filename in `ls` ; do
cd "$filename"
# Searching files
done
your script will not work witht the listing `ls`
as it would have files
and cd to a file would fail

try this,

Code:
for dirs in `ls -l | sed -n 's/^d.*[0-9] //p' | sed -e 's/ /#/'`
do
echo "${dirs}" | sed 's/#/ /'
#your operation here
done
 
Old 03-07-2006, 03:08 AM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
Quote:
I have a script, that is supposed to search for files in all directories. Here is the part of it
if your script is to find for files

why dont use find command from your home dir itself... i believe that would do
 
Old 03-07-2006, 03:28 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
?? for doesn't care about spaces. you don't need ls
Code:
primadA$  for f in *; do echo $f;done
HELLO THERE
add_framework.sc
check_conf_files.pl
functions.ksh
g
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
du or wc and file names with spaces bramadams Slackware 2 01-27-2005 11:43 AM
smbclient spaces in directory names? darkleaf Linux - Networking 2 11-23-2004 02:25 PM
directory-names with spaces... Schmurff Linux - Newbie 2 03-07-2004 11:06 AM
Files with spaces in their names downinthemine Linux - General 3 12-12-2003 01:48 PM
Windows director/file names with spaces. How to access them? correro Linux - General 3 03-10-2003 06:58 PM


All times are GMT -5. The time now is 01:21 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration