0

I'm new to Mac OS, I have a .sh file that contains a few instructions to startup Laravel server, React Native Metro server, ngrok etc.

When I execute with :

bash /Users/username/Desktop/proyectos/wooloveapp.com/laravelapp/scripts/app-startup-mac.sh 

I get the following error:

The file /Users/gabriel/Desktop/proyectos/laravelapp.com/laravelappcom/scripts/cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan serve does not exist.
The file /Users/gabriel/Desktop/proyectos/laravelapp.com/laravelappcom/scripts/cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan db:drop && php artisan db:create && php artisan migrate --seed does not exist.
The file /Users/gabriel/Desktop/proyectos/laravelapp.com/laravelappcom/scripts/ngrok http 8000 does not exist.
The file /Users/gabriel/Desktop/proyectos/laravelapp.com/laravelappcom/scripts/cd /Users/gabriel/Desktop/proyectos/woo && cd android  && gradlew clean && cd .. && npx react-native run-android -- --reset-cache does not exist.
The file /Users/gabriel/Desktop/proyectos/laravelapp.com/laravelappcom/scripts/cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan websockets:serve does not exist.

My script is simple, the locations are exact, for each line I want to open a terminal and execute the following actions on that same terminal, is there anything I'm doing wrong?

My script:

#!/bin/bash

open -a Terminal "cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan serve"

open -a Terminal "cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan db:drop && php artisan db:create && php artisan migrate --seed"

open -a Terminal "ngrok http 8000"

open -a Terminal "cd /Users/gabriel/Desktop/proyectos/woo && cd android  && gradlew clean && cd .. && npx react-native run-android -- --reset-cache"

open -a Terminal "cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan websockets:serve"

1
  • You can't do open -a Terminal "shell command to run", but there probably is no need for this.
    – nohillside
    Jun 15, 2023 at 16:57

2 Answers 2

1

Instead of trying to open five Terminals (which won't work because Terminal assumes whatever you pass as an argument is a file), you can put all the commands directly into your script.

#!/bin/bash
cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan serve
cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan db:drop && php artisan db:create && php artisan migrate --seed
ngrok http 8000
cd /Users/gabriel/Desktop/proyectos/woo/android && gradlew clean && cd .. && npx react-native run-android -- --reset-cache
cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan websockets:serve

If any of the php, ngrokor npx calls are blocking, add a & at the end of the command to run it in the background.

1

Let's look at the open man page:

NAME
     open – open files and directories

SYNOPSIS
     open [-e] [-t] [-f] [-F] [-W] [-R] [-n] [-g] [-j] [-h] [-u URL] [-s sdk]
          [-b bundle_identifier] [-a application] [--env VAR] [--stderr PATH] [--stdin PATH]
          [--stdout PATH] file ... [--args arg1 ...]
DESCRIPTION
     The open command opens a file (or a directory or URL), just as if you had double-clicked
     the file's icon. If no application name is specified, the default application as
     determined via LaunchServices is used to open the specified files.

"cd /Users/gabriel/Desktop/proyectos/laravelapp.com && php artisan serve" is not a filename.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .