[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "return" should not continue script execution, even if used inapprop
From: |
Robert Elz |
Subject: |
Re: "return" should not continue script execution, even if used inappropriately |
Date: |
Tue, 08 Jan 2019 08:45:37 +0700 |
Date: Mon, 7 Jan 2019 08:55:58 -0500
From: Greg Wooledge <wooledg@eeg.ccf.org>
Message-ID: <20190107135558.reqhfhr5vy3ih45g@eeg.ccf.org>
| https://mywiki.wooledge.org/BashFAQ/109
Which only works when the shell is bash...
dfong@dfong.com said:
| there's a good reason for the "craziness": it enables individual testing of
| the script's functions.
For that kind of use there's a trivial solution (as there often
is for cases when people are sure that the current definition
is inadequate).
If you have a script "dotscr" and you want to test it, then
you do ...
cat <<-EOF >run-dotscr
. ./dotscr
EOF
and then
sh run-dotscr # or bash, or mksh, or ...
You can probably abbreviate that as
sh -c '. ./dotscr'
What's more, if dotscr is as most scripts designed to be used
via the . command, and has no actual executable code (in the
sense that it consumes no input and produces no output, so
aside from checking for syntax errors, the above does nothing
useful) you can add extra commands into the run-dotscr script;
or as extra commands after a ';' in the -c case, to actually call
the functions dotscr defines, or the variables it creates, or
whatever it does which needs testing.
Or alternatively, interactively ...
sh # start a new shell (any appropriate shell)
. ./dotscr
# do whatever testing you lile
exit
Also, of course, it is also possible to write a script that can be
executed either via the '.' command, or as a standalone script,
if that is the desire - in fact many (perhaps most) scripts not
expressly designed to only work as "dot scripts" are like that.
The one piece of advice from that python related BashFAQ that
Greg referred to which is worth following is ...
Bash can do this, but it's not a natural style,
and you shouldn't be doing it.
kre
- "return" should not continue script execution, even if used inappropriately, Robert Hailey, 2019/01/05
- Re: "return" should not continue script execution, even if used inappropriately, Chet Ramey, 2019/01/06
- Re: "return" should not continue script execution, even if used inappropriately, Dennis Williamson, 2019/01/06
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately, Greg Wooledge, 2019/01/07
- Re: "return" should not continue script execution, even if used inappropriately,
Robert Elz <=
- Re: "return" should not continue script execution, even if used inappropriately, don fong, 2019/01/09
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/10
- Re: "return" should not continue script execution, even if used inappropriately, don fong, 2019/01/20
- Re: "return" should not continue script execution, even if used inappropriately, Greg Wooledge, 2019/01/21
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/20
- Re: "return" should not continue script execution, even if used inappropriately, konsolebox, 2019/01/24
- Re: "return" should not continue script execution, even if used inappropriately, don fong, 2019/01/24
- Re: "return" should not continue script execution, even if used inappropriately, konsolebox, 2019/01/24
- Re: "return" should not continue script execution, even if used inappropriately, Robert Elz, 2019/01/24
- Re: "return" should not continue script execution, even if used inappropriately, don fong, 2019/01/25