0

I am trying to make it easier to run a program which currently involves running multiple separate scripts. I just want to be able to run one .sh file which will then open multiple terminal windows and execute separate scripts in each window. I am having a problem now though where the scripts appear to be running (when I close the terminal windows it informs me that there is a process running), but nothing is being printed to the screen / console. It almost looks like the processes are being run silently in the background. I have simplified the program / scripts here to isolate the issue that I am having.

Here is the main shell script that is being used to call the others:

---main_script.sh---
echo "run my program"
gnome-terminal -- ~/Path/To/program_script_1.sh
sleep 2
gnome-terminal -- ~/Path/To/program_script_2.sh

And here are the two program scripts being called from the main script:

---program_script_1.sh---
bash
conda activate MyEnv
echo "do the first thing"
sleep 1
echo "done"
---program_script_2.sh---
bash
conda activate MyEnv
echo "do the second thing"
sleep 1
echo "done"

all of the shell scripts are in the same folder / directory.

When I run main_script.sh, it runs successfully, but it doesn't print anything to the console, so it's as if the programs are running in the background.

I think that the issue may be related to the fact that I am calling bash within the shell script, but this is necessary in order to be able to load my conda environment.

Here are some screenshots showing what it looks like after running (notice that there is no text output in the 2 program scripts): Program running output with no text printed

Output showing processes running in background

  • 3
    If you want your script to be run with bash, the first line should be `#!/bin/bash` or `#!/usr/bin/env bash`, not just `bash`. – Charles Duffy Feb 14 '23 at 20:31
  • 3
    And using `conda activate` in a script is... not generally reliable. `conda` may be configured to be sourced into your _interactive_ shells at startup, but that doesn't make it available to scripts. Running `eval "$(conda shell.bash hook)"` earlier in the script is the proper way to address that; see [calling conda source activate from bash script](https://stackoverflow.com/questions/34534513/calling-conda-source-activate-from-bash-script) – Charles Duffy Feb 14 '23 at 20:32

0 Answers0