ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
This script is passed two arguements, a filename pattern and a prefix. The problem seems to be in passing an arguement with wildcards (I had it working fine when the wildcards were in the script itself). This is a simple task, but I need this same methodology to improve a script for generating fade-transitions for key frame animations.
<code>
#!/bin/sh
list=(`ls "$1"`)
#echo ${list[@]}
for filename in "${list[@]}"
do
mv $filename $2"_"$filename
done
</code>
A sample call would go as follows
$ rnmpp *uhood-casc*png 13
Thanks for any help, I'm a new linux user but I love it!
the problem is that I need to use this kind of thing in other instances. From the current directory, I want to list the files of a certian designation, and assign each filename to an element in an array. Simply using the `ls *$1*png` will not work, because in these cases the interpreter runs this command every time through the for loop (and files that have been removed or renamed no longer show up, often immeadiately breaking the loop). There is clearly some subtlety in the syntax that I am overlooking.
Again, thanks for the help.
For example, I have a directory of many png files, and in particular I wish to rename all files begining with "final" to be prepended. If I use
list=`ls $1*png`
and pass "final" it will succesfully insert each matching png filenames into the array
however, if i use:
list=`ls $1`
and pass "final*png" it only hits the first matching file
Last edited by aliasofmike; 11-05-2007 at 02:36 PM.
Thanks macemoneta, the rename command will absolutely fill the needs of the script I've given as an example.
But I need to be able to do this particular thing in many other instances...not renaming files, but listing files that fit passed criteria and putting their names into an array. I imagine my error involves how the wildcard would be interepreted in the statement list=`ls $1` if the wildcards are part of the passed arguement.
Sorry for not being more clear before.
To test the problem I'm having, I made a test script as follows.
#!/bin/sh
ls $1
If I call test final*png it only prints the very first matching filename, as opposed to the list of matching filenames.
I know this must be a rudimentary mistake, so I apologize for wasting your time.
Last edited by aliasofmike; 11-05-2007 at 02:52 PM.
will pass the function all filenames that match the description, the substitution is of course done immeadiately, instead of passing the literal arguement to $1.
The only solution I know would be to require this syntax for calling the script
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.