-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathman_1_simple_shell
executable file
·145 lines (110 loc) · 3.73 KB
/
man_1_simple_shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
.\" Manpage for Shell
.TH dash 1 "24 March 2018" "1.0" "shell man page"
.SH NAME
hsh - interface to the Unix system kernel
.SH SYNOPSIS
$ [command] [-flags ]
.SH DESCRIPTION
A Shell provides you with an interface to the system kernel.
It gathers input from you and executes programs based on
that input. When a program finishes executing, it displays
that command's output followed by a new prompt.
.SH PROMPT
The prompt, $, which is called the command prompt, is
issued by the shell. While the prompt is displayed, you can
type a command.
Shell reads your input after you press Enter. It determines
the command you want executed by looking at the first word
of your input. A word is an unbroken set of characters.
Spaces and tabs separate words.
.SH OPTIONS
Built-ins
cd [arg]
Change the current working directory. The shell parameter
$HOME is the default if no directory is specified. If no
directory arg is found and the $CDPATH parameter contains
a list of directories separated by colons, each of these
directories is used as a prefix to arg in the given order,
and the current directory is set to the first one that is found.
$ cd /usf/lb
env
Prints the current environment
exit [n]
Causes the shell to exit with the exit status specified by
n. If n is omitted then the exit status is that of the last
command executed. (An end of file will also exit from the
shell).
Examples of Commands
pwd
Prints the name of the current directory. man pwd for more info
ls
Lists the files in the current working directory. man ls for more
info.
echo
Displays a string to standard output. man echo for more info.
sh
A shell program written by Ken Thompson. man sh for more info.
.SH ENVIRONMENT
Examples of Environment Variables
PATH
A list of directories for executables.
HOME
The default home directory of the system
USER
The user of the current system
PWD
The current parent directory
.SH SEE ALSO
sh(1), csh(1), environ(7), execve(2), exit(3), getline(3),
kill(2), malloc(3), perror(3), signal(2), strtok(3), wait(2),
_exit(2), isatty(3).
.SH EXAMPLE CODE
From Main Function:
#define _GNU_SOURCE
#include <stdio.h>
#include "holberton.h"
int main(int ac, char **av, char **env)
{
char *line, *newline;
size_t len = 0;
ssize_t characters;
char **tokenarray;
int cmdnum = 0;
(void)ac, (void)av;
while (1)
{
line = NULL;
len = 0;
cmdnum++;
if (isatty(STDIN_FILENO) == 1)
printprompt();
signal(SIGINT, ctrlc);
characters = getline(&line, &len, stdin);
if (characters == EOF || characters == -1)
return (ctrld(line));
if (line[0] == '\n')
{
free(line);
continue;
}
newline = _reallocchar(line);
if (newline == NULL)
{
free(line);
return (0);
}
tokenarray = tokensplit(newline);
if (tokenarray == NULL)
{
free(line);
free(newline);
return (0);
}
exec(tokenarray, env, av, line, newline, cmdnum);
free_all(line, newline, tokenarray);
}
}
.SH BUGS
Not discovered yet
.SH AUTHORS
Written by Derek Kwok and Elena Serebryakova