Execute a shell command when terminal start

How make the terminal run a script when it load?

Hey @Miguel_exe,

  1. You can create a start.sh script, put all the shell commands you would like to run in the start.sh file and in the package.json, add a start script like this:
"scripts": { 
    "start": "bash start.sh"
  },
  1. Or you can use the child_process module to run shell commands using Node.js.
const { exec } = require("child_process");

exec("ls", (error, stdout, stderr) => {
    if (error) {
        console.log(error.message);
        return;
    }
    if (stderr) {
        console.log(stderr);
        return;
    }
    console.log(`Output: ${stdout}`);
});

Hope this helps!

1 Like

im mean when image load it load a shell script
like ohmyzsh auto updater, it load when zsh loads up

You can put stuff in a .bash_profile script. It runs whenever you open a new terminal.

It will run globally (in all projects)
If yes i want it just for this project

if you want to run a script then i reccommend making it in one project and running CURL in the other to execute it

Ok, but i have the file
I need make bash run it without in other projects
Just in my project

so you just want it to run in one project, it always does because it can`t and should not really connect to another project

globally means it works all around the container instead of one folder

Try it. Yes, it will only run for the project you add the script to.

But i wanna run this script when terminal load
Not when project load

putting it in ,bash_profile will run the command when you open the terminal, not the project

But it will run the script globally? (in all projects)

no, it will run globally in all folders in that one project

So it means it will run in all projects or what?

no… the .bash_profile will only be read and executed by the project it is held in, it won`t be ran anywhere outside that container.

But .bash_profile file dosent exist

you make the file in the editor first

But glitch editor hide files what start with .
Except .env

yes, but you can write to it first. . files are only hidden to non-project members

But in terminal
I type ls -a
It have hidden . files in project

yes, that shows the hidden files.

okay, let me take you through this step by step. go to your editor out of the terminal in your project and make a new file called .bash_profile

reply when your done and can edit it

And now?

Im in phone so glitch is much buggy than pc

can i confirm that you are in the file now?

if so, you can put your commands there which will be executed on the terminal booting

does it work?

(more text for forum)

I dont know. The terminal is crashing the page because im in phone

which browser are you using?

Google Chrome. Last update

try firefox, the terminal works there aswell

It seems to work for the most part on DuckDuckGo also.

have you tried it yet?