0

I'm wanting this script to print 1,2,3.. without the use of functions, just execute two.sh then carry on where it left off, is it possible?

[root@server:~]# cat testing.sh                                  
#!/bin/bash
echo "1"
exec ./two.sh
echo "3"

[root@server:~]# cat two.sh                                     
#!/bin/bash
echo "2"
return
0

2 Answers 2

3

exec, if you give it a program name a, will replace the current program with whatever you specify.

If you want to just run the script (in another process) and return, simply use:

./two.sh

to do that.

For this simple case, you can also execute the script in the context of the current process with:

. ./two.sh

That will not start up a new process but will have the side-effect of allowing two.sh to affect the current shell's environment. While that's not a problem for your current two.sh (since all it does is echo a line), it may be problematic for more complicated scripts (for example, those that set environment variables).


a Without a program name, it changes certain properties of the current program, such as:

exec >/dev/null

which simply starts sending all standard output to the bit bucket.

Sign up to request clarification or add additional context in comments.

Comments

2

Sure, just run:

echo "1"
./two.sh
echo "3"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.