ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: ALT Devel discussion list <devel@altlinux.org>
Subject: Re: [devel] Q: shell "source" builtin
Date: Sat, 23 Jul 2005 03:50:50 +0400
Message-ID: <20050722235050.GA27606@basalt.office.altlinux.org> (raw)
In-Reply-To: <20050722231425.GX24898@solemn.turbinal.org>

[-- 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 --]

  reply	other threads:[~2005-07-22 23:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-22 23:14 Alexey Tourbin
2005-07-22 23:50 ` Dmitry V. Levin [this message]
2005-07-28  1:34   ` [devel] " Alexey Tourbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050722235050.GA27606@basalt.office.altlinux.org \
    --to=ldv@altlinux.org \
    --cc=devel@altlinux.org \
    --cc=devel@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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