You cannot read a file and in the meanwhile redirect your output to it.
What you can do is to use -i
parameter in sed
, that updates the file:
sed -i 's/def version = ".*"/def version = "'$version'"/' $file
You can see an example in https://stackoverflow.com/a/16901328/1983854 I posted yesterday.