Questions tagged [subshell]

A subshell refers to a shell invoked from within a parent shell. It is an example of a child process. Questions with this tag may involve any issue with working with subshells. Please also include tags for platform or shell language.

Most questions with this tag involve the Bash shell, as that is a very popular shell language. However this could relate to any platform, command-line application, or shell that allows the creation of subshells.

295 questions
1
vote
3 answers

getting the pid of a subshell command

I am trying to write a init service script for a java program. I have the following in the init script. $USER = awesomeuser $PROGRAM_CMD = "java -server com.test.TestClass" $PROGRAM_LOG = "/var/log/awesome_log" sudo -u $USER nohup $PROGRAM_CMD >>…
1
vote
1 answer

while loop in pipeline having side effects on Solaris /bin/sh but not Linux

I am running the same script under Linux and under solaris. Here is the script: #!/bin/sh index=0 ls /tmp | grep e | while read fileWithE do echo $fileWithE index=`expr $index + 1` done echo "index is $index" Since the while loop runs in a…
Melodie Gauthier
  • 685
  • 3
  • 12
  • 35
1
vote
2 answers

Scope of variables executing functions in a subshell

That's what happens when a command is executed in a subshell environment: The command will run in a copy of the current shell execution environment "Variable assignments and builtin commands that affect the shell's environment do not remain in…
TTK
  • 223
  • 6
  • 21
1
vote
1 answer

How is `(( ... ))` different from `( ... )`?

I wrote the following code: case "$2" in '+') ((res = $1 + $2 ));; '-') ((res = $1 - $2 ));; esac echo $res Usage example: ./"*filename*" 2 + 3 If I use double parentheses, ((res = $1 + $2 )) then the result gets printed.…
1
vote
6 answers

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…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
1
vote
1 answer

Having an issue passing variables to subshell

So here is my problem, I have this script I wrote where I'm exporting two variables however they're not making it into the subshell. The point of this script is to change a users password and clear out their pam_tally for CentOS and Ubuntu hosts.…
Kevin
  • 177
  • 1
  • 2
  • 6
1
vote
2 answers

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