Сценарии Bash - Как установить группу, с которой будут созданы новые файлы?

Этот не особенно полезен, но это чрезвычайно тайно. Я наткнулся на это при рытье вокруг в синтаксическом анализаторе Perl.

Прежде был POD, perl4 имел прием, чтобы позволить Вам встраивать страницу справочника, как nroff, прямо в Вашу программу, таким образом, это не потеряется. perl4 использовал программу, названную wrapman (см. страницу 319 Pink Camel для некоторых деталей) умно встроить nroff страницу справочника в Ваш сценарий.

работавший, говоря nroff игнорировать весь код и затем помещать суть страницы справочника после КОНЕЦ тег, который говорит Perl останавливать код обработки. Выглядевший примерно так:

#!/usr/bin/perl
'di';
'ig00';

...Perl code goes here, ignored by nroff...

.00;        # finish .ig

'di         \" finish the diversion
.nr nl 0-1  \" fake up transition to first page
.nr % 0     \" start at page 1
'; __END__

...man page goes here, ignored by Perl...

детали roff волшебства выходят из меня, но Вы заметите, что команды roff являются строками или числами в пустом контексте. Обычно константа в пустом контексте производит предупреждение. Существуют специальные исключения в op.c для разрешения пустых строк контекста, которые запускаются с определенных команд roff.

              /* perl4's way of mixing documentation and code
                 (before the invention of POD) was based on a
                 trick to mix nroff and perl code. The trick was
                 built upon these three nroff macros being used in
                 void context. The pink camel has the details in
                 the script wrapman near page 319. */
                const char * const maybe_macro = SvPVX_const(sv);
                if (strnEQ(maybe_macro, "di", 2) ||
                    strnEQ(maybe_macro, "ds", 2) ||
                    strnEQ(maybe_macro, "ig", 2))
                        useless = NULL;

Это означает, что 'di'; не производит предупреждение, но ни один не делает 'die'; 'did you get that thing I sentcha?'; или 'ignore this line';.

, Кроме того, существуют исключения для числовых констант 0 и 1, который позволяет пустое .00;. Код утверждает, что это было для более общих целей.

            /* the constants 0 and 1 are permitted as they are
               conventionally used as dummies in constructs like
                    1 while some_condition_with_side_effects;  */
            else if (SvNIOK(sv) && (SvNV(sv) == 0.0 || SvNV(sv) == 1.0))
                useless = NULL;

И что, Вы знаете, 2 while condition действительно предупреждает!

68
задан Rory 24 August 2009 в 08:40
поделиться

2 ответа

Команда newgrp используется для изменения текущего идентификатора группы во время сеанса входа в систему.

Новые каталоги, созданные в этом сеансе, будут иметь идентификатор группы, установленный командой.

newgrp (1)

12
ответ дан 24 November 2019 в 14:07
поделиться

There are a couple ways to do this:

  1. You can change the default group for all files created in a particular directory by setting the setgid flag on the directory (chmod g+s _dir_). New files in the directory will then be created with the group of the directory (set using chgrp

    ). This applies to any program that creates files in the directory.

    Note that this is automagically inherited for new subdirectories (as of Linux 3.10), however, if sub-directories were already present, this change won't be applied to them (use the -R flag for that).

  2. If the setgid flag is not set, then the default group will be set to the current group id of the creating process. Although this can be set using the newgrp command, that creates a new shell that is difficult to use within a shell script. If you want to execute a particular command (or set of commands) with the changed group, use the command sg .

    sg is not a POSIX standard command but is available on Linux.

168
ответ дан 24 November 2019 в 14:07
поделиться