Passing arguments from a file to a bash script
Assuming each line of arguments.txt
represents a separate argument, with bash 4 you can read arguments.txt
into an array using mapfile
(each line from the file goes in as an array element, in sequence) and then pass the array to the command
mapfile -t <arguments.txt
source test.sh "${MAPFILE[@]}"
The advantage is that splitting on spaces embedded inside lines is avoided
With lower versions of bash
IFS=$'\n' read -ra arr -d '' <arguments.txt
source test.sh "${arr[@]}"
You can do this with awk
. For example:
arguments=`awk '{a = $1 " " a} END {print a}' arguments.txt`
Edit after reading your comment:
arguments=`awk '{i = 0; while(i<=NF){i++; a = a " "$i}} END {print a}'