Re: renaming files via shell script



On 2006-02-23, robert wrote:

I still have one question: I can't get for 'file in "$@"' or 'for
file' to work. I can, however, get for file in "*mpc*" to work (mpc is
what I meant by somefile.

Here's my test case:

#!/bin/sh
echo "in script"
for file in "$@"
do
echo "in for loop"
done

I get 'in script' but not 'in for loop' .

The command I run is this, from the directory that has convert_mpc.sh

find . -type f -name "*mpc*" -exec ./convert_mpc.sh \;

My mistake; I left out {}:

find . -type f -name "*mpc*" -exec ./convert_mpc.sh {} \;

The files I have are like so (from same dir as convert_mpc.sh)

/home/iksrazal/mpc> find .
.
./mppdec-linux-libc6-static-1.95e.zip
./mppdec-static
./bc
./bc/01 - Stella By Starlight.mpc
./bc/02 - Autumn Leaves.mpc
./bc/03 - New Waltz.mpc
./bc/04 - Bouncing With Bud.mpc
./bc/05 - 'Round Midnight.mpc
./bc/06 - And Then Again.mpc
./bc/07 - I Thought About You.mpc
./bc/08 - Someday My Prince Will Come.mpc
./ozric_abs.mp3
./stella.mp3
./convert_mpc.sh

Now if I change the script to be the following, I get the 'in for loop'
message:

#!/bin/sh
echo "in script"
for file in "*mpc*"
do
echo "in for loop"
done

What am I doing wrong?

If you use that, find does nothing at all; you are not using its
output. Use that if you want to process files in the current
directory (and don't use find).

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages

  • Re: renaming files via shell script
    ... what I meant by somefile. ... I get 'in script' but not 'in for loop'. ...
    (comp.os.linux.misc)
  • Re: Variables not passed out of WHILE
    ... that values of a string are not passed out of a WHILE ... loop. ... My script will not ECHO the value of $var at the end. ...
    (comp.unix.shell)
  • Re: How to get an interation count from a while loop (bash)
    ... I am trying to count how many times a while loop iterates. ... echo Total Lines Read is $LOOP_COUNT ... The usage for this script is ... The usage for the above script is: ...
    (comp.os.linux.misc)
  • Re: How do I get this out?
    ... There are so many ways to retirve information from a database. ... I use a loop for the most of the time. ... echo $linkage; ... I've edit the script a bit and got rid of some of the complex scripts ...
    (alt.php)
  • Re: tcsh read loop
    ... > echo $line ... > Can this type of loop, that reads a complete line from a file, be done in ... You have to split this script into smaller scripts, and change STDIN. ...
    (comp.unix.shell)