Passing arguments from a file to a bash script
19
votes
3
answers
74589
views
I've got four files:
./
./myscript.sh
./arguments.txt
./test.sh
Inside myscript.sh
, I have to run the file test.sh
, passing to it the arguments contained inside arguments.txt
.
myscript.sh
is:
-bash
arguments=$(cat arguments.txt)
source test.sh $arguments
This works well *if arguments.txt
contains at most one* argument:
firstargument
The substitution is:
-shellsession
++ source test.sh 'firstargument'
But the problem is with two or more arguments. It does this:
-shellsession
++ source test.sh 'firstargument secondargument'
Also, I don't know in advance the number of arguments inside arguments.txt
. There can be zero or more.
Asked by Federico Ponzi
(744 rep)
Jul 21, 2014, 05:35 PM
Last activity: Oct 6, 2023, 02:50 PM
Last activity: Oct 6, 2023, 02:50 PM