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:

echo "in script"
for file in "$@"
echo "in for loop"

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

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

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

My mistake; I left out {}:

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

The files I have are like so (from same dir as

/home/iksrazal/mpc> find .
./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

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

echo "in script"
for file in "*mpc*"
echo "in for loop"

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 | <>
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'. ...
  • 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. ...
  • 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: ...
  • 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 ...
  • 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. ...