-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathman_1_simple_shell
95 lines (75 loc) · 3.76 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
.TH SIMPLE_SHELL 1 "April 03, 2022" "Holberton School" "General Commands Manual"
.SH NAME
.B hsh\fR \- A simple command interpreter (simple_shell)
.SH SYNOPSIS
.B ./hsh
.P
.B [command] [option]
.P
.B./hsh\fR [options] [command] | file
.P
.B /bin/[command] [option]
.SH DESCRIPTION
.LP
.B hsh\fR is a simple UNIX command language interpreter capable of executing commands Interactivly from \fBSTDIN\fR or piped from
a file.
Invocation
.P
hsh can be invoked both interactively and non-interactively. If hsh is invoked with standard input not connected to a terminal,it reads and executes received commands in order.If hsh is invoked with standard input connected to a terminal (determined by isatty(3)), an interactive shell is opened. When executing interactively, hsh displays the prompt #Shell_CL$ when it is ready to read a command.
Alternatively, if command line arguments are supplied upon invocation, hsh treats the first argument as a file from which to read commands. The supplied file should contain one command per line. hsh runs each of the commands contained in the file in order before exiting.
Environment
Upon invocation, hsh receives and copies the environment of the parent process in which it was exeucted. This environment is an array of name-value strings describing variables in the format NAME=VALUE.
Command Execution
.P
After receiving a command, hsh tokenizes it into words using " " as a delimiter. The first word is considered the command and all remaining words are considered arguments to that command. hsh then proceeds with the following actions:
1. If the first character of the command is neither a slash (\) nor dot (.), the shell searches for it in the list of shell builtins.If there exists a shell builtin by that name, the builtin is invoked.
2. If the first character of the command is none of a slash (\), dot (.), nor builtin, hsh searches each element of the PATH environmental variable for a directory containing an executable file by that name.
3. If the first character of the command is a slash (\) or dot (.) or either of the above searches was successful, the shell executes the named program with any remaining arguments given in a separate execution environment.
Exit Status
hsh returns the exit status of the last command executed, unless a syntax error occurs, with zero indicating success and non-zero indicatingfailure. All builtins return zero on success and one or two on incorrect usage (indicated by a corresponding error message).
.B Signals
.in +2n
While running in interactive mode, \fBshellby\fR ignores the keyboard input \fBCtrl+c\fR.
Alternatively, an input of end-of-file (\fBCtrl+d\fR) will exit the program.
.in
.TP
.B Builtin commands
.TP
.BR env
list all environment variables
.TP
.BR setenv " " [name] " " [value]
sets the "name" environment variable with to value "value" or updates it if it already exists
.TP
.BR unsetenv " " [name]
deletes the "name" environment variable from the enviroment variables
.TP
.BR cd " " [dir_path]
changes the current working directory to "dir_path"
.TP
.BR alias " " [name=[value] ...]
lists or sets command aliases
.TP
.BR Exit
exit the shell
.SH EXAMPLES
.B Interactive
vagrant@vagrant-ubuntu-trusty-64:~/simple_shell$ ./hsh
#Shell_CL$ ls
file0 file1 file2
#Shell_CL$ echo 123
123
#Shell_CL$ echo $?
0
#Shell_CL$ exit
vagrant@vagrant-ubuntu-trusty-64:~/simple_shell$
.B Non Interactive
vagrant@vagrant-ubuntu-trusty-64:~/simple_shell$ echo "pwd" | ./simple_shell
/home/vagrant/simple_shell
vagrant@vagrant-ubuntu-trusty-64:~/simple_shell$ echo "ls" | ./simple_shell
file0 file1 file2
--
.SH AUTHORS
Luis Manrique \fI<luismch158158@gmail.com>\fR
.P
Christian Varas \fI<christianvaras.2020@gmail.com>