subshell

Why does `cat <(cat)` produce EIO?

杀马特。学长 韩版系。学妹 提交于 2020-01-01 08:38:09
问题 I have a program that reads from two input files simultaneously. I'd like to have this program read from standard input. I thought I'd use something like this: $program1 <(cat) <($program2) but I've just discovered that cat <(cat) produces .... mmap2(NULL, 139264, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb758e000 read(0, 0xb758f000, 131072) = -1 EIO (Input/output error) .... cat: -: Input/output error and similarly, $ cat <(read -n 1) bash: read: read error: 0: Input/output

git branch vs $(git branch)

你离开我真会死。 提交于 2019-12-28 07:11:06
问题 When I execute git branch on the command line I get a list of all the branches on a repo, however when I execute $(git branch) in a sub-shell, it first prints out a list of files in the top level folder in a repo before printing out the branch names. Why? I'm basically trying to iterate over the branches using a for loop, but the listing of files breaks my script. for i in $(git branch); do echo $i done 回答1: $ git branch * master Try echo * master in your shell and see what you get? Hint: You

git branch vs $(git branch)

不问归期 提交于 2019-12-28 07:09:10
问题 When I execute git branch on the command line I get a list of all the branches on a repo, however when I execute $(git branch) in a sub-shell, it first prints out a list of files in the top level folder in a repo before printing out the branch names. Why? I'm basically trying to iterate over the branches using a for loop, but the listing of files breaks my script. for i in $(git branch); do echo $i done 回答1: $ git branch * master Try echo * master in your shell and see what you get? Hint: You

How do I activate a conda env in a subshell?

让人想犯罪 __ 提交于 2019-12-28 06:59:27
问题 I've written a python program. And if I have a shebang like this one: #!/usr/bin/python and I make the file executable with: $ chmod 755 program.py I can run the program like so: $ ./program.py Here is the issue. I use the conda virtual environments. When I run the program like above, the system creates a subshell that does not recognize the active environment: (my_env) $ ./program.py ImportError: No module named pymongo If I do it this way, however... (my_env) $ python program.py # blah blah

Left side of pipe is the subshell?

一笑奈何 提交于 2019-12-28 02:53:07
问题 Edit: My comment below regarding sed 's@^@ @' <(f1) is incorrect While $BASH_SUBSHELL indicates that we are in the same level as the launch, the variables are lost in the main script. based on Gordons answer I tested f1 > >(sed 's@^@ @') instead and that seems to work correctly. Still, shouldn't BASH_SUBSHELL should be 1 and not 0 for the first form? Consider this small test #!/bin/bash declare -i i=0 function f1() { let i++ echo "In f1, SUBSHELL: $BASH_SUBSHELL, i=$i" >&2 } f1 f1 | sed 's@^@

How to exit a Subshell

十年热恋 提交于 2019-12-25 07:40:11
问题 Basically, I am trying to exit a subshell that contains a loop. Here is the code: ` stop=0 ( # subshell start while true # Loop start do sleep 1 # Wait a second echo 1 >> /tmp/output # Add a line to a test file if [ $stop = 1 ]; then exit; fi # This should exit the subshell if $stop is 1 done # Loop done ) | # Do I need this pipe? while true do zenity --title="Test" --ok-label="Stop" --cancel-label="Refresh" --text-info --filename=/tmp/output --font=couriernew # This opens Zenity and shows

Parentheses for subshell don't work when stored in a variable

徘徊边缘 提交于 2019-12-25 04:24:30
问题 The command: ( echo 1 ) works fine when I input it in the command line but if I store it as a variable and call it, it gives the error: (echo: command not found Code: input="( echo 1 )" $input Why doesn't it evaluate the parentheses the same way and put it into a subshell when I call it this way? 回答1: This is discussed in full detail in BashFAQ #50. An unquoted expansion goes through only two stages of shell parsing: Field-splitting, and glob expansion. Thus, ( echo 1 ) is first split into

Sub-shell process not be able to access variables and functions defined in parent shell

别等时光非礼了梦想. 提交于 2019-12-24 04:10:55
问题 I have 3 scripts in the same directory, please find below contents of x.sh, y.sh and z.sh :- x.sh :- xData="DataOfX" function xInit(){ echo "xInit : data of a >$xData<" } y.sh :- . x.sh xInit sh z.sh zInit z.sh :- function zInit(){ echo "zInit of z" xInit } $@ Executing . y.sh in the same directory gives below output :- xInit : data of a >DataOfX< zInit of z z.sh: line 3: xInit: command not found How can a sub-shell process can access the variables and functions initialised in the parent

Does Powershell have an equivalent to the bash subshell?

拈花ヽ惹草 提交于 2019-12-24 00:38:45
问题 One thing that's really great in linux bash shell is that you can define variables inside of a subshell and after that subshell completes the (environment?) variables defined within are just gone provided you define them without exporting them and within the subshell. for example: $ (set bob=4) $ echo $bob $ No variable exists so no output. I was also recently writing some powershell scripts and noticed that I kept having to null out my variables / objects at the end of the script; using a

Unix Subshell inheriting the command history from parent bash

一个人想着一个人 提交于 2019-12-23 04:57:26
问题 I have written a series of python tools that spawn new bash sessions. I am want those individual subshells to inherit the command history of the parent. I have tried: shopt -s histappend PROMPT_COMMAND="history -an;$PROMPT_COMMAND" in the .bash_profile . But it didn't give me what I need. I have seen this done. My tool uses: os.system('bash') to spawn a subprocess. Thoughts? better way? 回答1: site.py sets os.environ at startup. This does not change unless you explicitly change os.environ. So,