BASH: Open a new terminal window and run a command

Open a terminal shell and run:
nano main.sh

Copy the following code and save the script:

    
    #!/bin/bash
    
    echo "Going to open a new terminal window and run a command..."
    
    osascript  <<EOF
    tell app "Terminal"
      do script "./otherscript.sh"
    end tell
    EOF
    
    echo "Welcome back!"
    

Create a new script:

    
    nano otherscript.sh

Copy the following code and save the script:

    
    #!/bin/bash
    
    echo "I am another script called main.sh"

Make the files executable:

    
    chmod +x main.sh
    chmod +x otherscript.sh
    

Do the test:

    
    ./main.sh
    

Leave a Reply

Your email address will not be published. Required fields are marked *