linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rick von Richter <rick.vonrichter@avnet.com>
To: vick Julius <julius_vick@hotmail.com>
Cc: linux-admin@vger.kernel.org
Subject: Re: shell script question:How 2 assign several fields from a file to a variable?
Date: Tue, 13 Sep 2005 23:08:50 -0700	[thread overview]
Message-ID: <4327BE72.30501@avnet.com> (raw)
In-Reply-To: <BAY20-F140F63F0ED660FA7ADE2259B9F0@phx.gbl>

I'm not sure you have the right logic in your script.  As I understand
it, you want to take each *.doc file and rename it to a filename from
names.txt.  For example; you have a.doc, b.doc, and c.doc. The way your
script is written, a.doc will be renamed (moved) to "Korean car", then
b.doc will be renamed to "Korean.car", and so will c.doc.  Your script
has two 'for' loops. The outer loop runs thru each file of *.doc, and
the inner loop cycles thru all of the entries in names.txt for EACH
*.doc file.  So, for each *.doc file (outer loop) it will completely run
thru the inner loop effective renaming each file to every file name you
have in names.txt eventually ending up with "Korean car" as the last
rename before it moves to the next *.doc file.  The effect of this will
be that every *.doc file will be renamed to "Korean car and the only
file you will have left in the directory will be the last *.doc file and
it will be called "Korean car".  Hmmm.

Anyways, to answer your question...  you need to use double quotes
around your input and output variables and commands.  Here is and example:

for i in "`cat names.txt`"; do
    printf "$i\n"
done

You could also use the 'echo' command instead or 'printf' but 'echo' is
outdated. Use printf.

HTH,
Rick

vick Julius wrote:

> Hello everybody
>
> I want to rename files with the new names from a text file, names.txt:
>
> Brazilian coffee
> Canadian maple
> Korean car
>
>
>
> i want to use the following script
>
> for i in *.doc
> do
>
>    for file in `cat names.txt`
>   do
>    mv  $i   $file....
>
>
>
> I want to renmae all files (in *.doc) with the new names read from
> names.txt file.
>
> The problem is the names in the file names.txt have spaces...
>
>
> Any idea?
>
> Thanks
>
> Vick
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's
> FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-admin" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2005-09-14  6:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-14  5:35 shell script question:How 2 assign several fields from a file to a variable? vick Julius
2005-09-14  6:08 ` Rick von Richter [this message]
2005-09-14 14:58   ` Scott Taylor
2005-09-14 15:36     ` freddie
2005-09-14  6:14 ` Jeff Woods
2005-09-14  6:41 ` Adrian C.

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=4327BE72.30501@avnet.com \
    --to=rick.vonrichter@avnet.com \
    --cc=julius_vick@hotmail.com \
    --cc=linux-admin@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;
as well as URLs for NNTP newsgroup(s).