[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Paul L. Snyder wrote:
>Quoting Art Alexion <art.alexion@verizon.net>:
>
>
>
>>I have a script that used to work called prepend.filename. It consists
>>of
>>
>>#!/bin/bash
>>
>>for file in ${2}
>>do
>>mv -v $file ${1}$file
>>done
>>
>>
>>I used to be able to run it like this
>>
>>prepend.filename Chipmunks- *.mp3
>>
>>and it would prepend Chipmunks- to every mp3 file in the current working
>>directory. Now strangely, it works on one file, then exits. Run it
>>again and it works on the next file and exits again. What went wrong?
>>
>>
>
>What's happening is that the shell is performing filename expansion
>before your script is executed.
>
<snip>
>
>If you change ${2} to ${1} in the script and quote your glob argument on
>the command-line, it should fix the problem:
>
>
>
>
<snip>
>As a further option, you could change ${2} to ${*}, which will expand
>to all of the command-line arguments. Then you will only need to quote
>your glob if any of the filenames have spaces. This would require a
>couple more changes to your script, to move 1ドル out of the way:
>
> #!/bin/bash
> PREFIX=${1}
> shift
> for file in ${*}
> do
> mv -v ${file} ${PREFIX}$file
> done
>
>
>
>
Thanks, Paul. Worked fine. Now I have to figure out *why* it worked,
that is, why it knew that {*} was the second argument, and why I needed
to assign the variable PREFIX to ${1}.
--
_______________________________________
Art Alexion
Arthur S. Alexion LLC
PGP fingerprint: 52A4 B10C AA73 096F A661 92D2 3B65 8EAC ACC5 BA7A
The attachment -- signature.asc -- is my electronic signature; no need for alarm.
Info @ http://mysite.verizon.net/art.alexion/encryption/signature.asc.what.html
Key for signed PDFs available at
http://mysite.verizon.net/art.alexion/encryption/ArthurSAlexion.p7c
The validation string is TTJY-ZILJ-BJJG.
________________________________________
Attachment:
signature.asc
Description: OpenPGP digital signature
___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug