Bash-how to properly READ and PASTE variables.

Recently i made a script for a project at molecular dynamics but am stuck at the last step.The thing i want to do is to ask the user to input the number of particles, then replace the bolded numbers at lines 9 and 17..

code

#!/bin/bash
#read number of particles
echo "insert the number of particles"
read particles
#convert text
#mv coordinates.txt coordinates
#main.in manipulation
#insert number of particles
sed 's/.*input_coord.*/particle 936  #input_coord/g' main.in > main.tmp; mv main.tmp main.in
#remove old coordinates
grep -Ev '#______' main.in  > main.tmp; mv main.tmp main.in
#add new coordinates
sed '/input_coord/ r coordinates' main.in > main.tmp; mv main.tmp main.in
#acf.f manipulation
#add number of particles
sed '3s/.*/      DATA ITM\/1000\/,IM\/936\//' acf.f > acf.tmp; mv acf.tmp acf.f
#xmd
../xmd/src/xmd main.in > timelog.out
#compile acf.f
..
blah
blah

I tried something like this

read particles
..
sed 's/.*input_coord.*/particle ${particles}  #input_coord/g' main.in >
or
sed 's/.*input_coord.*/particle $particles  #input_coord/g' main.in >

but still nothing..

Thank you in advance:)

Variables will never substitute in single quotes.

VAR="1234"
echo '${VAR}'
${VAR}
echo "${VAR}"
1234
$

/\

ty i figured it out..

i had to write it like this:

sed 's/.*input_coord.*/particle '${particles}' #input_coord/g' main.in >

close this thread mods:)