The code I have now
line=$(ps -A|awk '/$name/{print $1}')
doesn't seems working. What I want is use awk to search ps's output by process name and return the pid within my script
line=$(ps -A|awk -v name="$name" '$0 ~ name{print $1}')
See here for the right ways to access the values of shell variables in awk scripts.
line=$(ps -A|awk '/'$name'/{print $1}')
You are missing extra quote ' for $name
ps -Awo pid=,comm=on your system.