C-Shell
A simple shell written in C.
Loading...
Searching...
No Matches
internal_commands.h File Reference

This header file contains declarations for the internal commands. More...

#include <stdbool.h>

Typedefs

typedef bool option
 

Functions

int cd (int nargs, char **args)
 Change the shell working directory.
 
int echo (int nargs, char **args)
 Write arguments to the standard output.
 
int history (int nargs, char **args)
 Print the history of commands.
 
int ls (int nargs, char **args)
 List directory contents.
 
int pinfo (pid_t pid)
 
int pwd (int nargs, char **args)
 Print the full filename of the current working directory.
 
void quit_shell_with_status (int status)
 Quit the shell.
 
void quit_shell ()
 Quit the shell with status 0.
 
int search (int nargs, char **args)
 Search for a given file or folder under the current directory recursively.
 

Detailed Description

This header file contains declarations for the internal commands.

Typedef Documentation

◆ option

typedef bool option

Function Documentation

◆ cd()

int cd ( int nargs,
char ** args )

Change the shell working directory.

If no path is provided, changes the current directory to /.

◆ echo()

int echo ( int nargs,
char ** args )

Write arguments to the standard output.

Display the ARGs, separated by a single space character and followed by a newline, on the standard output.

Options:

  • -c - separate arguments with commas
  • -n - no newline at the end
  • -l - format output as a list

◆ history()

int history ( int nargs,
char ** args )

Print the history of commands.

If no option is specified, prints the last 5 commands.

Options:

  • -c - clear the history
  • -r - read the history file and write to the history list
  • -w - write the history list to the history file

◆ ls()

int ls ( int nargs,
char ** args )

List directory contents.

List information about the FILEs (the current directory by default).

Options:

  • -a - do not ignore entries starting with .
  • -l - use a long listing format

◆ pinfo()

int pinfo ( pid_t pid)

Sample output:

pid -- 231
Process Status -- {R/S/S+/Z}
memory -- 67854 {Virtual Memory}
Executable Path -- ./cshell

Process status codes:

  1. R/R+: Running
  2. S/S+: Sleeping in an interruptible wait
  3. Z: Zombie
  4. T: Stopped (on a signal)

Note: “+” must be added to the status code if the process is in the foreground.

Parameters
pidpid of the process, -1 for the parent process, 0 for the current process
Returns
int 0 on success, -1 on failure

◆ pwd()

int pwd ( int nargs,
char ** args )

Print the full filename of the current working directory.

If no option is specified, -P is assumed. Option -L overrides -P when both are used together.

Options:

  • -L - use PWD from environment
  • -P - resolves symlinks to get the current working directory.

◆ quit_shell()

void quit_shell ( )

Quit the shell with status 0.

◆ quit_shell_with_status()

void quit_shell_with_status ( int status)

Quit the shell.

Exits the shell with the given status.

Parameters
statusexit status

◆ search()

int search ( int nargs,
char ** args )

Search for a given file or folder under the current directory recursively.

Prints True or False to stdout depending on whether the file or folder exists.