I am new to shell scripting so apologies if this was asked before.
I have a file coordinates.txt like this:
765442
866447
755343
097754
I would like to pass each value of each line of the file to a variable and use those values one by one as input in a command line and save that number in part of the file name. I wrote the following code but not sure if this is the correct way to go...
cat coordinates.txt | while read LINE; do
var="$(echo $LINE)"
/home/users/scripts/TreeView/TreeView.sh -o $NAME_ALL.chr1.new_estimate.trees.$var --bp_of_interest $var
done
so in the output -o each value one at the time is appended to the file name and each value is also used as --bp_of_interest, one at the time
Any suggestion highly appreciated. Thanks
$NAME_ALL
? You need to double quote all variable expansions, andvar="$(echo $LINE)"
is better writtenvar="$LINE"
. Also, remove thatcat
and redirect the file into the loop withwhile read ...; done <coordinates.txt
. – Kusalananda Jul 23 '19 at 16:15