Skip to main content
Added code from comments
Source Link
Kusalananda
  • 356.3k
  • 42
  • 738
  • 1.1k

I have a script scriptA.sh that if a variable assume a certain value, it has to execute another script scriptB.sh that execute something and then call a scriptA.sh, that will call a scriptB.sh and so on.

I draw the execution:

ScriptA - ScriptB         
   |
   |
   _
            |
            _
   |
   |
   _
            |
            _

I have tried in this way but process are never closed

ScriptA.sh
./scriptB.sh &
exit

ScriptB.sh
./scriptA.sh &
exit

And also this way but process are never closed

ScriptA.sh
./scriptB.sh && exit

ScriptB.sh
./scriptA.sh && exit

Any suggestion?

The actual scripts:

scriptA.sh:

#!/bin/bash
val=123
directory_path=`pwd`
script_name=$0
if [ $val -eq 123 ];then
  echo "call B and exit"
  ./scriptB.sh $directory_path $script_name && exit 0
fi

scriptB.sh:

#!/bin/bash
directory_path=$1
exec_command=$2
cd
cd $directory_path
echo "call A and exit"
$exec_command && exit 0

I have a script scriptA.sh that if a variable assume a certain value, it has to execute another script scriptB.sh that execute something and then call a scriptA.sh, that will call a scriptB.sh and so on.

I draw the execution:

ScriptA - ScriptB         
   |
   |
   _
            |
            _
   |
   |
   _
            |
            _

I have tried in this way but process are never closed

ScriptA.sh
./scriptB.sh &
exit

ScriptB.sh
./scriptA.sh &
exit

And also this way but process are never closed

ScriptA.sh
./scriptB.sh && exit

ScriptB.sh
./scriptA.sh && exit

Any suggestion?

I have a script scriptA.sh that if a variable assume a certain value, it has to execute another script scriptB.sh that execute something and then call a scriptA.sh, that will call a scriptB.sh and so on.

I draw the execution:

ScriptA - ScriptB         
   |
   |
   _
            |
            _
   |
   |
   _
            |
            _

I have tried in this way but process are never closed

ScriptA.sh
./scriptB.sh &
exit

ScriptB.sh
./scriptA.sh &
exit

And also this way but process are never closed

ScriptA.sh
./scriptB.sh && exit

ScriptB.sh
./scriptA.sh && exit

Any suggestion?

The actual scripts:

scriptA.sh:

#!/bin/bash
val=123
directory_path=`pwd`
script_name=$0
if [ $val -eq 123 ];then
  echo "call B and exit"
  ./scriptB.sh $directory_path $script_name && exit 0
fi

scriptB.sh:

#!/bin/bash
directory_path=$1
exec_command=$2
cd
cd $directory_path
echo "call A and exit"
$exec_command && exit 0
Source Link
Cyr
  • 101
  • 1
  • 1

iterate script execution: A call B, B call A

I have a script scriptA.sh that if a variable assume a certain value, it has to execute another script scriptB.sh that execute something and then call a scriptA.sh, that will call a scriptB.sh and so on.

I draw the execution:

ScriptA - ScriptB         
   |
   |
   _
            |
            _
   |
   |
   _
            |
            _

I have tried in this way but process are never closed

ScriptA.sh
./scriptB.sh &
exit

ScriptB.sh
./scriptA.sh &
exit

And also this way but process are never closed

ScriptA.sh
./scriptB.sh && exit

ScriptB.sh
./scriptA.sh && exit

Any suggestion?