subshell

How to prevent command/script from changing global environment

I need to run scriptblocks/scripts from the current top-level shell and I want them to leave the global scope unmodified. So far, I've only been able to think of the following possibilities: powershell -file <script> powershell -noprofile -command <scriptblock> The problem is, that they are very slow. For instance, I would like to...

How can I tell from a within a shell script if the shell that invoked it is an interactive shell?

I'm trying to set up a shell script that will start a screen session (or rejoin an existing one) only if it is invoked from an interactive shell. The solution I have seen is to check if $- contains the letter "i": #!/bin/sh -e echo "Testing interactivity..." echo 'Current value of $- = '"$-" if [ `echo \$- | grep -qs i` ]; then echo ...

How to set bash trap again in trap code?

Hi, I have a bash function that is called must be called by an EXIT trap after the first time that it is called. The function sets the trap again to fire as soon as the function exits. echo 0 > .i function launchNextExperiment { ( # Run in nested subshell # Implement a mutex lock, not shown j=`cat .i` if [ $j -lt $k ] then t...