More shell scripts than one in one text file? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of More shell scripts than one in one text file? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am learning shell scripting for my introductory UNIX course at my university, and I`m curious if is it possible to have more than one shell script in one text file. What I mean by that is, for example in pascal when you have:

var…

begin
end.
//another program which will be ignore

compiler ignores anything after the end with period. Can something like this be done with Shell? I`m asking because I have to go through lot of Shell examples and having many files opened is not very handy, with this I could run the same script without worrying about u+x permissions and just run the script with same name anytime I go to the next code example. So it is possible to have something that will say: end, do not read any further. ? Thank you in anvance for answering this silly question.

Answer

For said purpose – that is stopping the script at any given line – you could simply use exit to break at this point. For any real life application this would seem a little crude though but for learning purposes it should fit.

Say:

#!/bin/sh

# now I am working here
do_something
exit

# this is old, do not execute
did_something
exit

# this is even older, do not execute
did_something_long_ago
We are here to answer your question about More shell scripts than one in one text file? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji