ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] Q: shell "source" builtin
@ 2005-07-22 23:14 Alexey Tourbin
  2005-07-22 23:50 ` Dmitry V. Levin
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Tourbin @ 2005-07-22 23:14 UTC (permalink / raw)
  To: devel

[-- Attachment #1: Type: text/plain, Size: 171 bytes --]

Как определить, запускается ли скрипт exec'ом или загружается через source?
Т.е. можно ли внутри скрипта отличить, запускают его или сорсят?

$ ./script
$ . ./script

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [devel] Q: shell "source" builtin
  2005-07-22 23:14 [devel] Q: shell "source" builtin Alexey Tourbin
@ 2005-07-22 23:50 ` Dmitry V. Levin
  2005-07-28  1:34   ` [devel] " Alexey Tourbin
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry V. Levin @ 2005-07-22 23:50 UTC (permalink / raw)
  To: ALT Devel discussion list

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

On Sat, Jul 23, 2005 at 03:14:25AM +0400, Alexey Tourbin wrote:
> Как определить, запускается ли скрипт exec'ом или загружается через source?
> Т.е. можно ли внутри скрипта отличить, запускают его или сорсят?
> 
> $ ./script
> $ . ./script

Вообще говоря, нет.

Но в некоторых случаях можно попробовать:

$ cat script.sh 
#!/bin/sh
echo "\$-=$-"
echo "\$0=$0"

$ ./script.sh 
$-=hB
$0=./script.sh

$ . ./script.sh
$-=bhimBH
$0=-bash

Зато можно сделать так, чтобы просто запустить было затруднительно:

$ cat script.sh 
#!/bin/sh /
echo "\$-=$-"
echo "\$0=$0"

$ ./script.sh 
/: /: is a directory


-- 
ldv

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [devel] Re: Q: shell "source" builtin
  2005-07-22 23:50 ` Dmitry V. Levin
@ 2005-07-28  1:34   ` Alexey Tourbin
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Tourbin @ 2005-07-28  1:34 UTC (permalink / raw)
  To: ALT Devel discussion list

[-- Attachment #1: Type: text/plain, Size: 549 bytes --]

On Sat, Jul 23, 2005 at 03:50:50AM +0400, Dmitry V. Levin wrote:
> On Sat, Jul 23, 2005 at 03:14:25AM +0400, Alexey Tourbin wrote:
> > Как определить, запускается ли скрипт exec'ом или загружается через source?
> > Т.е. можно ли внутри скрипта отличить, запускают его или сорсят?
> > 
> > $ ./script
> > $ . ./script
> 
> Вообще говоря, нет.

Эх, а в bash-2.05b/builtins/evalfile.c такая переменная хорошая есть,

    67  /* How many `levels' of sourced files we have. */
    68  int sourcelevel = 0;

плохо что снаружи её не видно.

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-07-28  1:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-22 23:14 [devel] Q: shell "source" builtin Alexey Tourbin
2005-07-22 23:50 ` Dmitry V. Levin
2005-07-28  1:34   ` [devel] " Alexey Tourbin

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git