LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-28-2006, 10:03 PM   #1
ankit_mcgill
Member
 
Registered: Aug 2005
Location: Montreal
Distribution: OpenSuse 10.3
Posts: 65

Rep: Reputation: 15
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
 
Old 04-28-2006, 10:31 PM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 41
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.
 
Old 04-28-2006, 10:36 PM   #3
ataraxia
Member
 
Registered: Apr 2006
Location: Pittsburgh
Distribution: Debian Sid AMD64
Posts: 296

Rep: Reputation: 30
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.
 
Old 04-28-2006, 10:41 PM   #4
ankit_mcgill
Member
 
Registered: Aug 2005
Location: Montreal
Distribution: OpenSuse 10.3
Posts: 65

Original Poster
Rep: Reputation: 15
thanks guys ... im sure this will do it !

ankit
 
Old 04-29-2006, 12:04 AM   #5
ankit_mcgill
Member
 
Registered: Aug 2005
Location: Montreal
Distribution: OpenSuse 10.3
Posts: 65

Original Poster
Rep: Reputation: 15
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 ??

Last edited by ankit_mcgill; 04-29-2006 at 12:27 AM.
 
Old 04-29-2006, 12:21 AM   #6
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
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?
 
Old 04-29-2006, 12:32 AM   #7
ankit_mcgill
Member
 
Registered: Aug 2005
Location: Montreal
Distribution: OpenSuse 10.3
Posts: 65

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Shell] Read a File from script yussef Programming 4 08-19-2008 04:26 AM
Shell Script.. Date format handling C-RAF. Programming 2 02-14-2006 08:34 AM
file renaming with shell script or ? XJNick Linux - General 5 07-29-2005 02:43 PM
File Parsing using a Shell Script yasir15 Programming 5 08-22-2003 12:17 PM
Search for a file using shell script sharathkv Linux - Newbie 2 08-06-2003 05:05 AM


All times are GMT -5. The time now is 12:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration