Andrew M. on 18 Apr 2019 15:24:27 -0700
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Determining when a shell script is sourced
|
- From: "Andrew M." <andrew.mitchell@fastmail.com>
- To: "Philadelphia Linux User's Group Discussion List" <plug@lists.phillylinux.org>
- Subject: Re: [PLUG] Determining when a shell script is sourced
- Date: Thu, 18 Apr 2019 18:24:18 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type; s=fm2; bh=75aP27TufIc8AWXCWlirki1TgxHCAWh 5C0cHMi600A4=; b=1O7lZVSkH50K18H481rWaJ1zwEbaXMuPDp6fPl4fRT/dqBI eJbaVV+dTEax0O4/JC+NIO4LbJ9gP7tKE0C4nCrg5ejTqCh2WcDCFKUi6CBl0rhY D4fzCISASE+HEaHmJowN+0F0vdy0CdfKm9wnrOJEU3UcaHYx7MF2f+QGn1+544+1 /1dTIY4vaZlzhyFmejTrmyDH/AN1W4syQu2jwWc487tyinsFftD//RXaykt0ECto D8Blgg2SQC+XfE1Zf6OgmK7VpAjCDz62dg3mQwUr5tJEMCDD+/1Ay4zl+0meS9HT nGE5xQuRjl0cG0SDOO7GZSDGtf/ldE5peQQrRqw==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=75aP27 TufIc8AWXCWlirki1TgxHCAWh5C0cHMi600A4=; b=fpdHIdwjvW6WDlo4G3pCPB EfUBKYFB2MUHr3OAdIQ13Dg5HzORJN8aNi0MyQRMVWfq39EDB6HIAdCVMm2Ch0j7 pZUiOmaxeB9ZsSZFzeipHzMq3FTWRK0PJB0rf8og4TvTB6ZMK/N5nNHDYisUJvMQ 5Wio23Na5MWVPO3CNC+r3tGGys/zLK5EW5/4tmp2qV1sWDqyCOD+UxTcy+lr2muL gCq9rGw80bk1coJMlDsmFZIMCZJqCce902DwPqoh0iL6XPxXXtX0r7zAq0bkClW8 9wiN7c21DlsFxGZdFtVrYqwBde6iJkvBh+OUKkLnwWazN24wVzIQUKfpm3wiIsww ==
- Reply-to: Philadelphia Linux User's Group Discussion List <plug@lists.phillylinux.org>
- Sender: "plug" <plug-bounces@lists.phillylinux.org>
- User-agent: Cyrus-JMAP/3.1.6-443-g918f9d3-fmstable-20190416v3
Had a few minutes to kill... How about this...
#!/usr/bin/env sh
# Try to execute a `return` statement,
# but do it in a sub-shell and catch the results.
# If this script isn't sourced, that will raise an error.
$(return >/dev/null 2>&1)
# What exit code did that give?
if [ "$?" -eq "0" ]
then
echo "This script is sourced."
else
echo "This script is not sourced."
fi
On Thu, Apr 18, 2019, at 5:28 PM, K.S. Bhaskar wrote:
We have a shell script (starts with #!/binsh and is at
https://gitlab.com/YottaDB/DB/YDB/blob/master/sr_unix/ydbinstall.sh) that should preferably not be source'd. Is there a way to test within the script whether someone has source'd it and generate an error without terminating the shell session that source'd it? Thank you very much.
Regards
– Bhaskar
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug