man pages section 3: Basic Library Functions

Exit Print View

Updated: July 2014



getusershell, setusershell, endusershell - get legal user shells


#include <unistd.h>

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


The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place:


The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells.

The setusershell() function rewinds the file or the list.

The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells.

Return Values

The getusershell() function returns a null pointer on EOF.


All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved.


Restricted shells should not be listed in /etc/shells.