getusershell(3)

๐Ÿ’– getusershell(3) ๐Ÿ’–

okay bestie, listen โ€” this is getusershell / setusershell / endusershell from the Library Functions Manual, and it's literally the bouncer-at-the-club of Unix login shells. you in the libc? you're gonna wanna know who's allowed in. ๐ŸŽ€


โœจ NAME โœจ

getusershell, setusershell, endusershell โ€” get permitted user shells ๐Ÿ’…

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc) โ€” the classic, no cap.

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

#include <unistd.h>

char *getusershell(void);
void setusershell(void);
void endusershell(void);

๐ŸŒธ Feature Test Macro Requirements for glibc ๐ŸŒธ

(peep feature_test_macros(7) if you need the lore, bestie)

  • getusershell(), setusershell(), endusershell():
    • Since glibc 2.21:
      • _DEFAULT_SOURCE
    • In glibc 2.19 and 2.20:
      • _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
    • Up to and including glibc 2.19:
      • _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
ngl the macro situation is giving โœจgenerational traumaโœจ but that's just how glibc grew up.

๐Ÿ‘‘ DESCRIPTION ๐Ÿ‘‘

so here's the tea.

The getusershell() function returns the next line from the file /etc/shells, opening the file if necessary. that line is supposed to contain the pathname of a valid user shell โ€” like, the receipts of who's even allowed to log in. ๐Ÿซถ

And here's the iconic plot twist: if /etc/shells does not exist or is unreadable, getusershell() behaves as if /bin/sh and /bin/csh were listed in the file. so it just goes "fine, these two then" and carries on, main character energy fr fr. ๐Ÿ˜ญ

The setusershell() function rewinds /etc/shells. โช rewinding the vibe check back to the start.

The endusershell() function closes /etc/shells. ๐Ÿšช and that's the door shut, bye.

๐Ÿ”ฅ RETURN VALUE ๐Ÿ”ฅ

The getusershell() function returns NULL on end-of-file. that's it, that's the whole clause. when the list runs out, it hits you with the NULL and you move on with your life. ๐Ÿ’€

๐Ÿ“ FILES ๐Ÿ“

  • /etc/shells

๐Ÿ’œ ATTRIBUTES ๐Ÿ’œ

For an explanation of the terms used in this section, see attributes(7). (iykyk)

  • Interface: getusershell(), setusershell(), endusershell()
    • Attribute: Thread safety
    • Value: MT-Unsafe
so uh, not thread safe, bestie. don't be sharing these across threads like they're a communal scrunchie. ๐Ÿ™ˆ

โญ STANDARDS โญ

None. ๐Ÿ˜Œ not a single one. it simply is what it is.

๐ŸŒˆ HISTORY ๐ŸŒˆ

4.3BSD. old money, honestly. vintage icon behavior. ๐Ÿ‘‘

๐Ÿ’ซ SEE ALSO ๐Ÿ’ซ


and that's a wrap on getusershell(3)! remember: this whole page came straight from Linux man-pages 6.20, dated 2026-02-08. slay, stay safe, and keep your shells valid ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms