![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| spaces in filenames, for do | naviztirf | Shell Programming and Scripting | 4 | 10-17-2007 05:08 PM |
| Unix filenames and spaces | x96riley3 | Shell Programming and Scripting | 2 | 01-31-2007 07:07 PM |
| how to handle spaces in filenames | rayne | Shell Programming and Scripting | 4 | 11-19-2006 01:37 PM |
| spaces in filenames | Hitori | Shell Programming and Scripting | 4 | 07-04-2006 04:35 PM |
| Strip leading and trailing spaces only in a shell variable with embedded spaces | jerardfjay | Shell Programming and Scripting | 6 | 03-07-2005 02:24 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
spaces in filenames
Hi
I hope someone will be able to resolve this little teaser! I am running a script for file in `ls directory` do echo "$file" ...other code here.... done this works fine unless we receive a file with a name which has a space in it ie "filena me" (I know its not good to have a space in a filename but we have no control over the filenames which are ftp'd to us.) If the file "filena me" is in the directory, the above script will do the following: filena ...do other stuff.... me ...do other stuff.... whereas I would like it to do filena me ....do other stuff.... Can anyone help me please? Thanks Helen ![]() |
|
||||
|
filenames starting with . and having spaces in filename
I am trying to run the following
for fname in * do echo $fname done to list all the files in a specific directory. This does not seem to include the files starting with . character (e.g .classpath) then i modified the program to include ls -A for fname in $(ls -A) do echo $fname done This is including the . files. But it splits the file containing spaces into multiple entries (Hello name.txt => Hello, name.txt) Just wondering is there a way to modify the * option to include the hidden files. Any help is very much appreciated. Thanks ben |
|
||||
|
Think the other way round...
Hi Ben,
I think "ls -A" is the best way to go, using "ls * .*" will also list contents of directories, even above, and I guess You don't want that. Well, just a guess anyway. One of the beauties of ls (and many other utilities) is that when piped to another program it will regard each file/entry as a line, as opposed to when written to screen where it will all appear continuously, also when produced as a string for the "for fname in " construct. So if You use "while" and try something like this instead, Code:
ls -A | while read fname ; do echo $fname ; done Code:
ls -A|while read line;do [ -f "$line" ] && echo $line;done |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|