LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-16-2009, 05:15 AM   #1
shl
LQ Newbie
 
Registered: Nov 2003
Location: Prague, Czech Rep.
Distribution: Debian
Posts: 9

Rep: Reputation: 0
Question program takes as a parameter file name; how to use redirection instead?


Hi all,

I have a program, which takes as a parameter a file name like this:

./program --input-file /tmp/the_input_file

and this /tmp/the_input_file contains list of files like:

/tmp/file1.txt
/tmp/file2.txt
....
/tmp/fileN.txt

OK, now is there a way how to give the program the file list, without having to create a file containing the list?

something like (this didn't work):
./program --input-file < `ls -1 /tmp/file*.txt`

thanks a lot, Asen.
 
Old 08-16-2009, 05:47 AM   #2
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by shl View Post
Hi all,

I have a program, which takes as a parameter a file name like this:

./program --input-file /tmp/the_input_file

and this /tmp/the_input_file contains list of files like:

/tmp/file1.txt
/tmp/file2.txt
....
/tmp/fileN.txt

OK, now is there a way how to give the program the file list, without having to create a file containing the list?

something like (this didn't work):
./program --input-file < `ls -1 /tmp/file*.txt`

thanks a lot, Asen.

put it in a for loop

Code:
for file in `ls /tmp/file*.txt`
do 
./program --input-file $file
done
 
Old 08-16-2009, 06:24 AM   #3
shl
LQ Newbie
 
Registered: Nov 2003
Location: Prague, Czech Rep.
Distribution: Debian
Posts: 9

Original Poster
Rep: Reputation: 0
loop doesnt work

thanks for your answer.

the problem is that loop doesn't work.
the program needs the full list of files at the beginning.

What I need is some way to redirect the output of ls, so that it looks to the program like a file containing list of files.

Hope what I wrote makes at least a bit of sense ;-)
 
Old 08-16-2009, 07:32 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Code:
./program --input-file $(ls -1 /tmp/file*.txt)
The -1 option is unnecessary and it is safer to ensure ls is not an alias (it usually is!) giving unexpected output, leading to
Code:
./program --input-file $(/bin/ls /tmp/file*.txt)
That will work as long as you don't have whitespace characters in the /tmp/file*.txt names.

Edit:

Sorry, I misunderstood your requirement. Now I understand ./program requires a file but you don't want to make one. Hmm! Not as self-contradictory as it sounds if ./program is written to follow the *n*x convention of accepting filename "-" (without the quotes) as meaning standard input.

If it does then this will work
Code:
echo $(/bin/ls /tmp/file*.txt) | ./program --input-file -
It all depends on how ./program is written.

Last edited by catkin; 08-16-2009 at 07:39 AM.
 
Old 08-16-2009, 11:36 AM   #5
shl
LQ Newbie
 
Registered: Nov 2003
Location: Prague, Czech Rep.
Distribution: Debian
Posts: 9

Original Poster
Rep: Reputation: 0
Thumbs up this worked, thanks

this worked, thanks
 
  


Reply



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
any cl program to show how much space something takes up? kryptobs2000 Linux - Software 1 10-29-2007 03:16 PM
Newbie Bash Program Problem with Redirection LNewbie Programming 14 03-18-2007 10:25 AM
linux bash - how to use a dynamic parameter in shell parameter expansion expression nickleus Linux - General 2 08-21-2006 04:54 AM
pass a parameter to a running program nimra Linux - Software 1 06-29-2004 01:38 AM
How to change function parameter value and return back to the main shell program Bassam Linux - General 1 01-26-2004 10:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:28 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration