<> == How can two unrelated processes communicate? == Two unrelated processes cannot use the arguments, the environment or stdin/stdout to communicate; some form of inter-process communication (IPC) is required. === A file === Process A writes in a file, and Process B reads the file. This method is not synchronized and therefore is not safe if B can read the file while A writes in it. A lockdir or a signal can probably help. === A directory as a lock === `mkdir` can be used to test for the existence of a dir and create it in one atomic operation; it thus can be used as a lock, although not a very efficient one. Script A: {{{ until mkdir /tmp/dir;do # wait until we can create the dir sleep 1 done echo foo > file # write in the file this section is critical rmdir /tmp/dir # remove the lock }}} Script B: {{{ until mkdir /tmp/dir;do #wait until we can create the dir sleep 1 done read var < file # read in the file this section is, critical echo "$var" # Script A cannot write in the file rmdir /tmp/dir # remove the lock }}} See [[http://mywiki.wooledge.org/BashFAQ/045|Faq #45 ]] and [[http://wiki.bash-hackers.org/howto/mutex | mutex]] for more examples with a lock directory. === Signals === Signals are probably the simplest form of IPC: ScriptA: {{{ trap 'flag=go' USR1 #set up the signal handler for the USR1 signal # echo $$ > /tmp/ScriptA.pid #if we want to save the pid in a file flag="" while [[ $flag != go ]]; do # wait for the green light from Script B sleep 1; done echo we received the signal }}} You must find or know the pid of the other script to send it a signal using kill: {{{ #kill all the pkill -USR1 -f ScriptA #if ScriptA saved its pid in a file kill -USR1 $(