Posts

Showing posts with the label posix

Why are heredoc redirections not allowed before a while loop

Image
Clash Royale CLAN TAG #URR8PPP Why are heredoc redirections not allowed before a while loop The POSIX Shell Command Language allows redirections to follow compound commands. The standard says (emphasis mine) The shell has several programming constructs that are "compound commands", which provide control flow for commands. Each of these compound commands has a reserved word or control operator at the beginning, and a corresponding terminator reserved word or operator at the end. In addition, each can be followed by redirections on the same line as the terminator . Each redirection shall apply to all the commands within the compound command that do not explicitly override that redirection. For aesthetic reasons I want to put a heredoc before my while loop as in <<'RECORDS' while foo:bar baz:quux ... RECORDS IFS=: read -r A B do # do something with A and B done because it makes the code easier to follow. However, it doesn't work in the shells I tried it (...

Are multiple sources in nsswitch.conf merged for getpwent?

Image
Clash Royale CLAN TAG #URR8PPP Are multiple sources in nsswitch.conf merged for getpwent? Say I made a custom nss module called foo which defines abides by the required API: foo #include <nss.h> enum nss_status _nss_foo_getpwnam(const char *name, struct passwd *result, char *buf, size_t buflen, int *errnop); enum nss_status _nss_foo_getpwuid(uid_t uid, struct passwd *result, char *buf, size_t buflen, int *errnop); enum nss_status _nss_foo_setpwent(void); enum nss_status _nss_foo_getpwent(struct passwd *result, char *buf, size_t buflen, int *errnop); enum nss_status _nss_foo_endpwent(void); Assuming I have my nsswitch.conf setup like so: passwd: foo files It is clear from the standard that getpwnam() for user bar would first call my _nss_foo_getpwnam() and then if that returns NSS_STATUS_NOTFOUND , check /etc/passwd . However, the standard and behavior for [set|get|end]pwent() is a bit less clear to me. If I understand man 5 nsswitch.conf correctly, it sounds like this would...