Bash script call another script

#! /bin/kshecho "prova". ./second.shecho "ho lanciato il secondo". ./third.shecho "ho lanciato il terzo"

echo "sono nel seconcarry out script"dosomething1exit $?If detects an error and also exits through condition -9, exits constantly.How I have the right to do stop exiting from the initially shell if the boy shell exits?

I can"t modify

You watching: Bash script call another script



What you"re doing here is including and as sub-scripts running in the same procedure, which is dubbed “sourcing” in shell programming. . ./ is basically indistinguishable to including the text of at that allude. The departure command exits the process, it does not matter whether you contact it in the original script or in a sourced script.

If all you desire to do is run the commands in and also and also they don"t have to accessibility or modify variables and attributes from the original script, speak to these scripts as son processes.

#! /bin/kshecho "prova"./second.shecho "ho lanciato il secondo"./3rd.shecho "ho lanciato il terzo"If you need the other scripts to access variables and also functions from the original manuscript, yet not modify them, then call these scripts in subshells. Subshells are sepaprice processes, so exit exits only them.

See more: Could Not Be Saved Because The Source File, Fix: Firefox ' Could Not Be Read'

#! /bin/kshecho "prova"(. ./ "ho lanciato il secondo"(. ./ "ho lanciato il terzo"If you have to usage variables or attributes characterized in and in the parent manuscript, then you"ll must save sourcing them.

The return builtin exits only the sourced manuscript and also not the entirety procedure — that"s among the few distinctions in between consisting of an additional manuscript with the . command also and also consisting of its text in the parent script. If the sourced scripts just contact departure at the toplevel, as opposed to inside functions, then you can readjust leave into return. You can carry out that without editing the script by utilizing an alias.

See more: Surface Pro 4 Trackpad Not Working : Touchpad Fixed (All Models)

#! /bin/kshecho "prova"alias exit=rerotate. ./second.shecho "ho lanciato il secondo". ./3rd.shunalias exitecho "ho lanciato il terzo"If leave is additionally dubbed inside attributes, I do not think there"s a non-cumbersome method. A cumbersome method is to set an departure trap and put your code there.

#!/bin/kshdo_initially () echo "prova" trap "after_second" EXIT . ./ after_secondafter_second () echo "ho lanciato il secondo" trap "after_third" EXIT . ./ after_thirdafter_3rd () trap - EXIT echo "ho lanciato il terzo"do_first