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
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.
public MyClass() { URL url = getClass(). getResource("filename. txt"); File file = new File(url. getPath()); InputStream input = new FileInputStream(file); // ... }
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 .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With