Re: Enhancement to psql command, feedback.

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Steven Lembark <lembark(at)wrkhors(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Enhancement to psql command, feedback.
Date: 2018-05-10 15:50:42
Message-ID: CA+bJJbxD1cUYMA4o4BhgEcwDdT+dA7ph8Nz0tCe+c6KQ8Dbrhw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, May 10, 2018 at 4:46 PM, Steven Lembark <lembark(at)wrkhors(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2018-05-10 15:52:48 Re: Selecting strict, immutable text for a composite type.
Previous Message Francisco Olarte 2018-05-10 15:33:56 Re: Domain based on TIMEZONE WITH TIME ZONE