LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   file handling shell script (http://www.linuxquestions.org/questions/programming-9/file-handling-shell-script-439874/)

ankit_mcgill 04-28-2006 11:03 PM

file handling shell script
 
hello everyone,

i have got a simple question.

wat i want to do is to make a shell script that can take a path to dir as argument and then go thru the directory and in the process assign the name of the file to a variable in the script lets say $fname.

the reaon i want to do this is coz i have a idv tag editting utility so i would like this script to assign the name of the file in the dir to $fname and then call this prog with the filename.

thanks for all the help
ankit

taylor_venable 04-28-2006 11:31 PM

Here's a Bourne-shell script that'll do it:
Code:

#!/bin/sh
for x in `ls -1A $1`; do
    echo $x
done

It prints out all the names of the files in the given directory, just modify the commands inside the loop and you'll be good to go.

ataraxia 04-28-2006 11:36 PM

You don't need a real script to do this - you can use "find". I used it for the very same purpose:
Code:

find /path/to/music -type f -exec tag_editor {} \;
This will run "tag_editor [i]filename[i]" for every file in /path/to/music.

ankit_mcgill 04-28-2006 11:41 PM

thanks guys ... im sure this will do it !

ankit

ankit_mcgill 04-29-2006 01:04 AM

Quote:

Originally Posted by ataraxia
You don't need a real script to do this - you can use "find". I used it for the very same purpose:
Code:

find /path/to/music -type f -exec tag_editor {} \;
This will run "tag_editor [i]filename[i]" for every file in /path/to/music.


Hi i tried ur method in a script ... one problem though .. i should have mentioned this is my earlier post....

this methos executes the command "tag_editor" on all the files ... but the prog i wanna run requires input from the user ... so any way for this to wait for the user to input the data ??

perfect_circle 04-29-2006 01:21 AM

Quote:

Originally Posted by ankit_mcgill
Hi i tried ur method in a script and i got the err
Code:

find: missing argument to `-exec'
any ideas ??

What exactly did you execute?

ankit_mcgill 04-29-2006 01:32 AM

hey,

sorry .. the command worked fine ... was a typo ... but as i said is there a way for it to wait for the user to input something .... ?

thanks
ankit


All times are GMT -5. The time now is 08:54 AM.