6

I have a set of file names whom I have to insert as command-line arguments while my bash script is running. Is there any way to give command line arguments using a separate file (like "test.txt")?

Let's assume these are the files: fileA, fileB, FileC, FileC, FileD, and let's assume the bash script is testBash.sh

4
  • 1
    arguments are in test.txt file? Commented Apr 23, 2014 at 5:56
  • can you change the testBash file? Commented Apr 23, 2014 at 5:59
  • Hello Rahul, Yes arguments are in a test.txt file Commented Apr 23, 2014 at 6:00
  • Hello طاهر I can change the testbash.sh scriptطاهر Commented Apr 23, 2014 at 6:05

2 Answers 2

3

yes easily using xargs. assume file content is

A
B

and the bash script file s content is

echo $1
echo $2
echo $@

then :

cat file | xargs ./s

A
B
A B
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, طاهر Thank you very much for your help... :) you have clearly mentioned about how to do that.... :)
One should remember xargs can split an argument list to multiple invocations of the same command, at an arbitrary place. So it's not proper for long lists. (In practice, this is done near ARG_MAX, but this isn't guaranteed.)
3

If I understand the question correctly, and test.txt contains a list of file names you want to pass to testBash.sh, you should be able to do something like this:

cat test.txt | testBash.sh

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.