Date: Mon, 19 Aug 2019 22:39:53 +0530 From: Mihir Luthra <luthramihir708@gmail.com> To: freebsd-hackers@freebsd.org Subject: undefined behaviour of return statement in /bin/sh and missing man entry Message-ID: <CAEa=dYBsOcmrkf=sOFwPY0-TJDbY_ooMzqDDth4SBAGV0BXpUQ@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Hi everyone, Recently I was writing script on my virtual machine where I needed to know If a /bin/sh script has been sourced. I found many ways on stackoverflow, most of which only seem to work for bash. Although after some research, I found a way that should have worked with /bin/sh. It was that if I executed return from a function or sourced script, it should work fine and in other cases it should have wrote to stderr. Although on executing return on command line I got logged out and on executing same on non-login shells it just exited. Also, there seem to be no entry for return statement on man page of sh. [1] I have posted a brief explanation for the same in my stackoverfow question. [2]. [1] https://www.freebsd.org/cgi/man.cgi?query=sh&manpath=Unix+Seventh+Edition [2] https://stackoverflow.com/questions/57547626/detect-if-a-script-has-been-sourced-in-bin-sh Kind Regards, Mihir
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAEa=dYBsOcmrkf=sOFwPY0-TJDbY_ooMzqDDth4SBAGV0BXpUQ>