Question

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

Was it helpful?

Solution

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top