public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: Karthik Vishwanath <karthikv@Alum.Dartmouth.ORG>
To: Newbie List <linux-newbie@vger.kernel.org>
Subject: files and directories with spaces in bash script
Date: Mon, 26 Mar 2007 10:59:17 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0703261049190.13397@localhost> (raw)

Hello,

I am trying to write a script to organize/sort my music collection. All of 
my music is arranged as Artist/Album folders with tracks within them, and 
most of these names have spaces (if not other strange characters). The 
script I am trying to get working needs to get all filenames in a 
specified directory so that I can process each file at a time. I am trying 
to do this as:

#!/bin/bash
# set_idv3_tags.sh

for directory in "$@"; do
   if [[ -d "$directory" ]]; then
     for f in `find $directory -iname '*mp3' `; do
       echo "found mp3 file: $f"
     done
   fi
done


Obviously, $f is getting word-split at each space encountered in 
$directory as well as in the filename. How can I set bash to give me an 
array/variable that I loop over for each file found only, irrespective of 
spaces without using sed to replace the spaces with _ etc.?

I did think of -print0, but could not get to loop over each file and I 
prefer not to use ls. What are my options with bash, or is it just better 
to get this written with Perl?


Thanks!

-K

-- 
The only way to keep your health is to eat what you don't want, drink
what you don't like, and do what you'd rather not.  -- Mark Twain
-
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:[~2007-03-26 14:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-26 14:59 Karthik Vishwanath [this message]
2007-03-26 15:52 ` files and directories with spaces in bash script Robin Doer
2007-03-26 16:05   ` Karthik Vishwanath
2007-03-27 11:49     ` Cedric
2007-03-28 18:10 ` Flemming Greve Skovengaard

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=Pine.LNX.4.64.0703261049190.13397@localhost \
    --to=karthikv@alum.dartmouth.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