Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get command-line arguments using a text file?

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

like image 540
Madura Dissanayake Avatar asked Apr 23 '14 05:04

Madura Dissanayake


People also ask

How do I get command line arguments?

If you want to pass command line arguments then you will have to define the main() function with two arguments. The first argument defines the number of command line arguments and the second argument is the list of command line arguments.

How do you pass an argument to a text file in Java?

public MyClass() { URL url = getClass(). getResource("filename. txt"); File file = new File(url. getPath()); InputStream input = new FileInputStream(file); // ... }

How do I get command line arguments in Linux?

On Linux, if you only need to get the args , the command is ps -o args -p <pid> and it will only print the args or use -o cmd if you only need to see the cmd .


1 Answers

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
like image 98
Taher Khorshidi Avatar answered Sep 28 '22 02:09

Taher Khorshidi