Shutter closes when executing a bash script

I am writing my first bash script, so sorry noobie-ness.

He called hello.bash, and here is what it contains:

#!/bin/bash
echo Hello World

I did

chmod 700 hello.bash

to give me permissions to execute.

Now when i type

exec hello.bash

My putty terminal shuts down instantly. What am I doing wrong?

+3
source share
1 answer

From the man page for exec:

If a command is given, it replaces the shell without creating a new process. If no command is specified, redirection can be used to change the current shell environment.

So, your script process starts instead of your terminal, and when it ends, your terminal too. Just do instead:

./hello.bash
+11
source

Source: https://habr.com/ru/post/1768166/


All Articles