Linux Newbie help
 help / color / mirror / Atom feed
From: Jim Reimer <jdr@wa5rrh.org>
To: robin@robind.de
Cc: linux-newbie@vger.kernel.org
Subject: Re: File names with spaces
Date: Tue, 18 Feb 2003 07:59:09 -0600	[thread overview]
Message-ID: <3E523C2D.2050101@wa5rrh.org> (raw)
In-Reply-To: 20030218093623.1FB578D8FE@basicbox3.server-home.net

robin@robind.de wrote:
> 
> A solution should look like this:
> 
> for file in `ls -1`; do
>   newfile=`echo "$file" | sed 's/ /_/'`
>   echo "File is named ${file}"
>   echo "The new file is named ${newfile}"
> 
>   mv "$file" "$newfile"
> done
> 
> IHMO in the main-loop it is better to choose "ls -1", so the field
> separator is \n and there's only one filename in each line.
> The next <big> thing is to put the filename into quotations. Now a
> filename, even with spaces, will be interpreted as one word.

Robin, that still doesn't work right - try it and see:

$echo > file\ 001
$echo > file\ 002
$ ./test.sh
File is named file
The new file is named file
File is named 001
The new file is named 001
File is named file
The new file is named file
File is named 002
The new file is named 002
$

The previously referenced Bash Scripting Guide has the answer.
Change the for statement to read:
for file in *; do
and it will work.

$ ./test.sh
File is named file 001
The new file is named file_001
File is named file 002
The new file is named file_002
$

-jdr-






-
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

  reply	other threads:[~2003-02-18 13:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-18  9:36 File names with spaces robin
2003-02-18 13:59 ` Jim Reimer [this message]
2003-02-28 23:46 ` Mike Castle
  -- strict thread matches above, loose matches on Subject: below --
2003-02-17 19:11 Theo. Sean Schulze
2003-02-17 20:34 ` Brian Jackson
2003-02-18 21:37   ` Theo. Sean Schulze
2003-02-20 10:22     ` J.

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=3E523C2D.2050101@wa5rrh.org \
    --to=jdr@wa5rrh.org \
    --cc=linux-newbie@vger.kernel.org \
    --cc=robin@robind.de \
    /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