From: "Theo. Sean Schulze" <tschulze@teamfinders.org>
To: linux-newbie <linux-newbie@vger.kernel.org>
Subject: [SOLVED] Re: File names with spaces
Date: Thu, 20 Feb 2003 18:13:32 +0100 [thread overview]
Message-ID: <20030220171332.GA4937@teamfinders.org> (raw)
In-Reply-To: <Pine.LNX.4.21.0302201111260.32557-100000@hestia>
J.,
Thanks for your suggestions. While googling comp.unix.shell today, I found yet another method. I was not aware that "*" when used by itself matches every filename in a directory. Apparently, part of the problem I was having was a side effect of ls and find. Here is the script that I used:
#!/usr/bin/bash
for file in *
do
newfile="`echo "$file" | tr '[:blank:]' '[_*]'`"
mv "$file" "$newfile"
done
I also learned something important about tr. I was using [:space:], but that is not appropriate here. [:space:] includes horizontal as well as vertical whitespace. That means I was transforming linefeeds as well as spaces. [:blank:] is exclusively horizontal whitespace, which is what I needed.
Thanks to all of you who contributed. I appreciate your help.
Cheers,
Sean
On Thu, Feb 20, 2003 at 11:22:36AM +0100, J. hunted and pecked out:
> On Tue, 18 Feb 2003, Theo. Sean Schulze wrote:
>
> > Thanks, that did help, although it didn't solve the problem.
> > I now recognize that the problem is in assigning the variable.
> > Both my version with ls and the version with find in the example give
> > the expected results when printing to the console,
> > but they both fail when used to assign a string including spaces to a
> > variable. I need to find a way to maintain the integrity of the string
> > as I assign it to the file variable. I tried `echo (ls -1)` and `echo
> > "(ls -1)"`, but neither works. Changing the parentheses to brackets
> > doesn't help either.
> >
> > Cheers,
> > Sean
>
> Assigning variables does not happen in the `ls -1' statement. This only
> generates strings. You need a command that read's the variables correctly.
> Use `read', as in:
>
> ls -1 | while read file ; do echo "$file" ; done
>
> or
>
> find . -type f | while read file ; do
> echo "$file"
> done
>
> or more exotic, array version.
>
> IFS=$'\n' eval 'lines=( $(cat < $file) )'
> # now you have a array of lines.... which can be proccessed further..
>
> These all where tested and work just fine.
>
> G00d lUcK
>
> J.
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
--
Theo. Sean Schulze
tschulze@teamfinders.org
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
next prev parent reply other threads:[~2003-02-20 17:13 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-17 19:11 File names with spaces Theo. Sean Schulze
2003-02-17 20:34 ` Brian Jackson
2003-02-18 21:37 ` Theo. Sean Schulze
2003-02-20 10:22 ` J.
2003-02-20 17:13 ` Theo. Sean Schulze [this message]
2003-02-20 19:43 ` [SOLVED] " J.
2003-02-21 8:59 ` J.
2003-02-23 13:30 ` Theo. Sean Schulze
2003-02-23 14:12 ` Problem installing avi libraries Peter Howell
2003-02-23 15:25 ` Ray Olszewski
2003-02-23 14:46 ` [SOLVED] Re: File names with spaces J.
2003-02-21 7:29 ` file transfer via telnet ichi
2003-02-20 20:10 ` Nathan
2003-02-20 21:44 ` Eckhardt, Rodolpho H. O.
2003-02-21 8:27 ` Jos Lemmerling
2003-02-21 8:51 ` J.
2003-02-21 18:55 ` whitnl73
2003-02-22 9:55 ` Thiago F.G. Albuquerque
2003-02-22 10:16 ` J.
2003-02-22 15:59 ` whitnl73
2003-02-22 16:03 ` whitnl73
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030220171332.GA4937@teamfinders.org \
--to=tschulze@teamfinders.org \
--cc=linux-newbie@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox