Re: Enhancement to psql command, feedback.

Поиск
Список
Период
Сортировка
От Francisco Olarte
Тема Re: Enhancement to psql command, feedback.
Дата
Msg-id CA+bJJbxD1cUYMA4o4BhgEcwDdT+dA7ph8Nz0tCe+c6KQ8Dbrhw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Enhancement to psql command, feedback.  (Steven Lembark <lembark@wrkhors.com>)
Список pgsql-general
On Thu, May 10, 2018 at 4:46 PM, Steven Lembark <lembark@wrkhors.com> wrote:
> The whole point of "#!" working in shell is that the two-bytes
> (a) mark the file as executable by a specific shell command and
> (b) are a shell comment.

Shebang is an unix-ism. It is not part of the shell. The shell just
execs whatever you tell it to.

In a simple way, in unix when a file is marked executable the loader
is called to load and execute it. The loader first looks at the start
of the file to try to determine what it is ( it does not use the
'extension' for this as MSDOS and friends ). If it is one of the
several formats binary formats, like elf or a.out, it understands it
loads and executes. If it is the magic sequence "#!" it tries to
search for another executable ( NOT A SHELL COMMAND, this works even
if you zap all the shells in your computer ) and recursively invokes
it ( this is done by execve(2) in my linux machine, and described in
its manual page ).

No shell involved:

folarte:~/tmp$ type cat
cat is /bin/cat
folarte:~/tmp$ echo -e '#!/bin/cat\nHello there\nGood bye then' > xx
folarte:~/tmp$ chmod +x xx
folarte:~/tmp$ ./xx
#!/bin/cat
Hello there
Good bye then
folarte:~/tmp$ perl -e 'exec("./xx")'
#!/bin/cat
Hello there
Good bye then

You can try other ways to call execv*, nothing magical in the perl
way, just avoiding the shell ( which has an exec builtin command, with
different behaviour from typing a command name, which does fork, wait
in the parent, execv in the child ).

Francisco Olarte.


В списке pgsql-general по дате отправления:

Предыдущее
От: Francisco Olarte
Дата:
Сообщение: Re: Domain based on TIMEZONE WITH TIME ZONE
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Selecting strict, immutable text for a composite type.