I would like to kill the xterm process I started this way in a script:#!/bin/bashecho #!/bin/bash > /tmp/test0grep file | awk '{print xterm -hold -e echo,$1,sleep 10 && pid=$!}' >> /tmp/test0echo exit >> /tmp/test0chmod 700 /tmp/test0bash /tmp/test0&sleep 5kill $pid  ---> does not workexitnow let's say, I have got several xterm launched this way in the same bash (test0), is there a way to store their corresponding pid in an array and call them back when it's time to kill them? Furthermore, when storing these values, is there a way to associate them with another value (in this example with $1) to make it easier to call back. nb: $1 = textthank you very much !
kill xterm process in a bash
process;kill;xterm
When you run the script with:bash /tmp/test0&you're starting an entirely separate bash process and putting it in the background. You can't see the variables defined in that script; they belong to the other process. If you want to get access to variables defined in another file, load that file into your current bash process using the . or source command:. /tmp/test0After that, you'll be able to say $pid in your main script and get the value that was set in the other file.All of that said  the way you're structuring things is very puzzling. The script you've posted has a lot of other errors that I assume are from editing the real one down for the question (you use $! as though it's an awk variable, but then expect the variable you copied it into to be defined in the Bash script, for example, and test0 would have many syntax errors). $! is only defined in Bash after a background process is run with &: even if your awk command worked, $pid would be empty. If you want to get a hold of the xterm process's PID in that way, you need to run it as xterm ... &. bash /tmp/test0 & puts the test0 script in the background, rather than the xterm command.It seems like you'd be better off getting rid of test0 altogether, and just launching xterm from the main script. It's probably worth having a rethink about how you're going about things at a higher level. At the very least, look at what's in your real test0 file and see whether it's what you actually want.