I have a shell script that generates and runs a shell script. I need to get hold of a variable that is set once the generated script is run. testVar script:
#!/bin/bash
echo "#!/bin/bash" > testGen
echo "somePid='12345' # this is actually set by a program" >> testGen
echo "echo \"somePid set to: \${somePid}\"" >> testGen
/bin/bash ./testGen # execute the generated script
echo "somePid after exec: ${somePid}" # how to get the ${somePid}?
How can I get ${somePid} ? Expected output:
$ ./testVar
somePid set to: 12345
somePid after exec: 12345
sourcethe other script (or use the equivalent.command), so it runs in the same shell. But... why create another script rather than just executing commands directly? It seems like an overcomplicated and fragile way to do things.