Re: Enhancement to psql command, feedback. - Mailing list pgsql-general

From Francisco Olarte
Subject Re: Enhancement to psql command, feedback.
Date
Msg-id CA+bJJbxD1cUYMA4o4BhgEcwDdT+dA7ph8Nz0tCe+c6KQ8Dbrhw@mail.gmail.com
Whole thread Raw
In response to Re: Enhancement to psql command, feedback.  (Steven Lembark <lembark@wrkhors.com>)
List 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 by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: Domain based on TIMEZONE WITH TIME ZONE
Next
From: Tom Lane
Date:
Subject: Re: Selecting strict, immutable text for a composite type.