Repository navigation
Expand file tree
/
Copy pathhsh.1
More file actions
176 lines (145 loc) · 3.63 KB
/
Copy pathhsh.1
File metadata and controls
176 lines (145 loc) · 3.63 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
.\" Manpage for hsh
.TH HSH 1 "January 2026" "Holberton School" "User Commands"
.SH NAME
hsh \- simple UNIX command interpreter
.SH SYNOPSIS
.B hsh
.br
.B hsh
.RI [ command " " argument ... ]
.br
.B echo "ls" | hsh
.SH DESCRIPTION
The
.B hsh
program is a simple command-line interpreter written in C as part of the Holberton School curriculum.
It provides a minimal set of features similar to the standard UNIX shell
.BR sh (1) ,
allowing users to execute system commands and access environment variables.
The shell supports both interactive and non-interactive usage, basic PATH resolution, and a limited set of built-in commands.
.SH MODES OF OPERATION
.TP
.B Interactive mode
Runs when standard input is connected to a terminal. The shell displays the prompt:
.PP
($)
and waits for user input.
Example:
.pp
($) ls -l
($) echo Hello World
.TP
.B Non-interactive mode
Runs when input is redirected or piped into the shell. Commands are executed sequentially without printing a prompt.
Example:
.PP
$ echo "ls" | hsh
$ echo "ls -l" | ./hsh
.SH BUILT-IN COMMANDS
The following built-in commands are implemented:
.TP
.B exit
Exit the shell. This command takes no arguments and returns the exit status of the last executed command.
This command causes the shell to terminate.
.TP
.B env
Print the current environment variables, one per line, in the format
.I name=value .
.SH COMMAND EXECUTION
The shell executes commands according to the following logic:
.PP
1. If the command contains a slash '/', it is treated as a file path.
2. Otherwise, the shell searches for the executable in the directories listed in the
.B PATH
environment variable.
3. If found, the shell creates a new process using
.B fork (2)
and replaces the child process image using
.B execve (2).
4. The parent process waits for the child to terminate using
.B waitpid (2).
5. The exit status of the last command is stored and returned by the shell.
.SH RETURN VALUES
The return value of
.B hsh
is the exit status of the last executed command.
The following exit codes may be returned:
.TS
tab(@);
l l.
Code@Description
0@Successful execution or EOF (Ctrl+D)
1@Internal error (fork or waitpid failure)
126@Permission denied / Command not executable
127@Command not found
128 + n@Command terminated by signal n
.TE
.SH ERROR MESSAGES
Error messages are printed to
.B stderr
following this format:
.PP
.nf
hsh: line_number: command: error_message
.fi
Examples:
.PP
.nf
hsh: 3: aaa: not found
hsh: 5: ./dir: Permission denied
hsh: 7: /bin/shh: No such file or directory
.fi
.SH ENVIRONMENT
.TP
.B PATH
A colon-separated list of directories in which the shell searches for commands.
The environment is passed unchanged to executed programs.
Example:
.PP
PATH=/usr/local/bin:/usr/bin:/bin
.SH LIMITATIONS
This educational shell does not support:
.PP
\- Complex command lines
\- Command separators (; , &&, ||)
\- Pipes (|)
\- Redirections (<, >)
\- Wildcards (*) or globbing
\- Environment variable expansion ($VAR)
\- Job control (&, fg, bg)
\- Aliasing or command history
.SH EXAMPLES
Interactive usage:
.PP
.nf
$ ./hsh
($) ls
file.c hsh shell.h
($) /bin/pwd
/home/user/simple_shell
($) env
PATH=/usr/bin:/bin
HOME=/home/user
($) exit
.fi
Non-interactive:
.PP
.nf
$ echo "ls" | ./hsh
file.c hsh shell.h
.fi
.SH AUTHOR
Written by Morgane (Alreix) as part of the Holberton School curriculum.
.SH FILES
.TP
.I hsh
The shell executable.
.TP
.I hsh.1
This manual page.
.SH SEE ALSO
sh(1), bash(1), execve(2), fork(2), waitpid(2), environ(7)
.SH CREDITS
Developed as part of the Holberton School Low-Level Programming curriculum.
.SH COPYRIGHT
This project is provided for educational purposes only.