Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putty closes on executing bash script

Tags:

bash

putty

I am writing my first ever bash script, so excuse the noobie-ness.

It's called hello.bash, and this is what it contains:

#!/bin/bash
echo Hello World

I did

chmod 700 hello.bash

to give myself permissions to execute.

Now, when I type

exec hello.bash

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

like image 337
xbonez Avatar asked Oct 06 '10 02:10

xbonez


People also ask

How do you stop putty from closing?

To ensure that the ssh session windows does not close and to view the error message on the server side, set 'Close Window on exit' to 'Never' under the Session tab as shown below. This is useful in troubleshooting ssh failure during ssh access to the remote ssh gateway.

How do I run a .sh file in putty?

“run sh file in putty” Code Answer ./script-name-here.sh #Chage the "script-name-here" to the name of the . sh file.


1 Answers

From the man page for exec:

If command is supplied, it replaces the shell without creating a new process. If no command is specified, redirections may be used to affect the current shell environment.

So your script process runs in place of your terminal and when it exits, so does your terminal. Just execute it instead:

./hello.bash
like image 157
ars Avatar answered Nov 14 '22 22:11

ars