-
Notifications
You must be signed in to change notification settings - Fork 1
/
text.txt
executable file
·443 lines (381 loc) · 18.1 KB
/
text.txt
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
GNU Readline library
https://tiswww.case.edu/php/chet/readline/readline.html
basics Shell
https://www.youtube.com/watch?v=hMSByvFHOro&list=PLGU1kcPKHMKj5yA0RPb5AK4QAhexmQwrW
command lines:
chsh -s /bin/zsh //changing terminal shell to zsh
chsh -s /bin/bash //changing terminal shell to bash
PS1= "else" //changing prompt name
pushd /Downloads //jumping from a dir to
popd //come back
file .git //what kind of file
locate .... //search
which ... //which command is installed
cal //calender
history //comand lines tiped
!numberfromhistory //exec the line from history
whatis ... //short description of the command
apropos ... //search for command related to ...
find ... //find
printf > xxx.txt //writes in file
echo > xxx.txt //writes in file
less ... //print the file like cat but read from the top
grep 'abc' ./file/ //search for word in a file
sed "s/[ab]/c/g" //replace every a or b by a c
| //piping take the result before | to do what is after
sort //sort
./ //execute a shell script
sudo !! //!! = last command line typed
kill //stops a program running
xkill //to kill a process clicking on it
ping google.com //check if yout connected
wget http... //to download a file on internet
date //date
bc //calculator
set | less //envirronement of bash
. .bashrc //relaod the .bashrc file
> //redirection
directories:
./bashrc //file to edit the settings
alias xxx='xxx ls' //is like #define xvariable (shortcut)
function () {} //function
/etc/bashrc //main file of bash
script:
#!/bin/sh //hashbang
echo "Hello World!"
exit
Functions used: add_history, malloc, rl_on_new_line, rl_redisplay,
signal, fork, free, write, execve, waitpid, rl_replace_line,
isatty, getenv, readline, open, perror,
Functions autorised:
rl_clear_history,
printf, access, read,
close, wait, wait3, wait4,
sigaction, sigemptyset, sigaddset, kill, exit,
getcwd, chdir, stat, lstat, fstat, unlink,
dup, dup2, pipe, opendir, readdir, closedir,
strerror, ttyname, ttyslot, ioctl,
getenv, tcsetattr, tcgetattr, tgetent, tgetflag,
tgetnum, tgetstr, tgoto, tputs
receive command
read commant
interpret command (search the directory of the command)
execute the command
MANDATORY:
prompt, historic, PATH, ', ", >, >>, <, <<, |, $, $?, ctrl-C, ctrl-D, ctrl-\
◦ echo with option -n
◦ cd uniquement avec un chemin relatif ou absolu
◦ pwd
◦ export // add line to envirronement
◦ unset
◦ env
◦ exit
BONUS:
&&, ||, ()
wildcards *
redirections:
standard input //user keyboard
standard output, error output //on screen ouput
< write in file
> capture from file
<< >> write or capture to the end of file
-what is a node? the line, a art of the line? from env
-what is g_status?
-what is isatty?
-explain $?
-ft_isvariable not understand
-child process finished?
workflow
main
|->t_minishell data;
|->init_minishell
|->init env
|->ft_array_size
|->ft_split_env
|->ft_strchr(line, '=')
|->ft_create_new_node
t_env *result;
|->ft_insert_at_end
|->init_term_fd
|->data->std_in = dup(STDIN_FILENO);
|->data->std_out = dup(STDOUT_FILENO);
while
{
signal_handler
display_prompt_msg
|->readline
|->add_history
|->ft_ctrl_d
|->isatty
ft_commands
|->ft_has_valid_quotes
|->ft_count_commands
|->ft_strchr_variable
|->if ((raw_cmd[i] == '$' && ft_isalnum(raw_cmd[i+1]) && s_quote == 0))
|->ft_get_export_id
|->ft_check_var_rules
|->ft_parse_variables
|->ft_strchr_variable
|->ft_get_export_id
if (ft_strcmp(variable, "?") == 0)
return (ft_replace_string(data->raw_cmd, variable, ft_itoa(g_status.status)));
else
{
if (ft_isvariable(data->lstenv, variable))
{
tmp = ft_find_id(data->lstenv, variable);
result = ft_replace_string(data->raw_cmd, tmp->id, tmp->value);
}
else
result = ft_replace_string(data->raw_cmd, variable, "");
return (result);
}
|->ft_init_data_one_cmd
|->ft_redirect
|->get_filename
in_or_from_file
|->signal
|->is_builtin
|->fork
|->signal
|->exec_one
|->find_command_route_env
|->ft_isvariable
|->getenv
|->command_add
|->access
|->execve
|->ft_free_one
|->ft_multiple_commands
|->ft_check_pipe_sytax
|->ft_separate_cmds
|->pipe
|->signal
|->fork
|->signal
|->child_process ?
|->exec_multiple
->find_command_route_env
|->ft_isvariable
|->getenv
|->command_add
|->access
|->execve
|->reset_term_fd
}
return (g_status.status);
LEAKS
leaks -atExit -- ./minishell leaks result
echo ok
echo hola ok
echo hola hola ok
echo "hola" ok
echo "hola hola" ok
echo " hola hola " ok
echo -n hola ok
echo hello -n ok
echo -nnnnnnnn ok
echo -nnnnnnnn a ok
echo -nnnnnnnn -nnnnnnnn hello world ok on bash wrights hello world
echo "hola " " hola" ok
echo $PWD ok
echo \n ok
echo '"Bienvenue sur malekal.com"' ok
echo "'Bienvenue sur malekal.com'" ok
echo $'hola' ok return = $'hola' and must be: hola
echo text files are: *.txt ok return = text files are: *.txt and must be: text files are: text.txt test.txt
echo "hola hola" > test.txt ok
echo $PATH ok
echo "$PATH" ok
echo "rep and files on system: $(LS)" ok return = rep and files on system: $(LS) and mus be: text.txt
echo a "" b "" c ok
echo a "$NO_SUCH_ENV" b $NO_SUCH_ENV c
unset NO_SUCH_ENV ok not working like bash
echo tab not working
echo "$ $ $ $ $ $ " ok builtin
echo $ ok ...
echo $? ok
exit ok
ctrl-C empty prompt ok
ctrl-D empty prompt ok
ctrl-\ empty prompt ok
ctrl-C with text ok
ctrl-D with text ok
ctrl-\ with text crash
ctrl-C after cat
mkdir dir ok
cd dir ok
pwd ok
cd .. ok
cd ./ ok
cd ../../ ok
cd / ok
touch testfile ok
cd testfile ok minishell: cd: testfile: Permission denied
cd NO_FILE ok minishell: cd: NO_FILE: No such file or directory
cd /bin ok
cd ok
cd /bin/../ ok
ENV
export HOME= ok
unset HOME ok
export HOME="./" ok
export HOME="../../" ok
export HOME="" ok
export HOME="/BIN" ok
export HOME=a ok
export HOME=NO_SUCH_FILE ok
export CDPATH="/" ok
exit ok
exit 0 ok
exit 1 ok
exit -1 ok
exit 2147483647 ok
exit 2147483648 ok
exit -2147483648 ok
exit -2147483649 ok
exit -- 42 ok
exit " 42 " ok
exit -- -- 42 ok
exit --42 ok
exit ++42 ok
exit 42 42 ok reprint exit
exit ab ok
exit 1a ok
exit + ok
exit - ok
exit " " ok
exit 0 0 ok "
exit 0 0 | echo hello crash
export HELLO=hello; echo $HELLO ok
export HELLO=hello; echo $hello ok
export HELLO=hello; echo "$HELLO" ok
export TEST="echo hello"; $TEST ok
export abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890=hello
echo $abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 not working
export TEST="export TEST=echo"; $TEST hello; $TEST hello not working
export | grep -v -E '^declare -x _=' no end
export 1 _+ _OK _2? _OK2=VAR =NG OK3= is like bash
> file crash
> file | cat < no_such_file no end
echo hello > out1.txt > out2.txt > out3.txt 2> err1.txt 2> err2.txt 2> err3.txt
cat out1.txt out2.txt out3.txt err1.txt err2.txt err3.txt ok hello 222?
echo hello >> out1.txt >> out2.txt >> out3.txt 2>> err1.txt 2>> err2.txt 2>> err3.txt
cat out1.txt out2.txt out3.txt err1.txt err2.txt err3.txt ok not like bash
ls > out1.txt > out2.txt > out3.txt 2> err1.txt 2> err2.txt 2> err3.txt
cat out1.txt out2.txt out3.txt err1.txt err2.txt err3.txt ok not good
ls >> out1.txt >> out2.txt >> out3.txt 2>> err1.txt 2>> err2.txt 2>> err3.txt
cat out1.txt out2.txt out3.txt err1.txt err2.txt err3.txt ok not good
ls no_such_file > out1.txt > out2.txt > out3.txt 2> err1.txt 2> err2.txt 2> err3.txt
cat out1.txt out2.txt out3.txt err1.txt err2.txt err3.txt ok not good
ls no_such_file >> out1.txt >> out2.txt >> out3.txt 2>> err1.txt 2>> err2.txt 2>> err3.txt
cat out1.txt out2.txt out3.txt err1.txt err2.txt err3.txt ok npt good
echo a > out ok
echo b >> out; echo c >> out; echo d >> out; cat out ok
echo a > out; echo b >> out; echo c >> out; echo d > out; cat out ok
echo hello 2147483647 > file ok
echo hello 2147483648 > file ok
unset ok
unset; env | grep -v -E '^_=' | sort no end
unset A; echo $A, export A='test $A' ok ???
unset _A1; echo $_A1, export _A1='test $_A1' ok ???
unset A B C; echo $A$B$C$D, export A=test B=multiple C=var D=hello ok not working
unset A B = invalid C; echo $A$B$C$D, export A=test B=multiple C=var D=hello ???
unset PWD; echo $PWD ok
unset OLDPWD; echo $OLDPWD ok
unset NO_SUCH_ENV; echo $?$NO_SUCH_ENV ok not good
unset 1 ok
unset A=a; echo $A, export A=a ok not a valid identifier
unset ' \"$&`\n' ok not a valid identifier
syntax error
| ok
> ok
>> ok
>>> ok
< ok change perror name
< > ok change perror name
| echo ok
echo | | ok not sure if good or not
cat < > ok cahnge name
echo ' ok to check
echo " ok to check
Evaluation check second try
- make -n ko
- compilation without error ok
- no relink ok
- command with abolute path cd /users/mamita ok
- no global variable used
- global variable check ok
- empty command ok
- space and tabs 2 x tab has a different comportment
- no crash ok
- working? ok
- absolute path with args cp text.txt txt.txt ok
ls -s
- multiple time ok
- no crash ok
- working? ok
- echo ok
- exit ok
- command + arg + echo $? ok
- check printed value ok
- multiple and wrong ok
- expr $? + $? ok
- no crash ok
- working? ok
- ctrl-C empty prompt ok
- ctrl-\ empty prompt ok
- ctrl-D empty prompt ok (prints exit)
- ctrl-C with text ok
- enter ok
- ctrl-D with text ok
- blocking command + ctrl-C ok (prints ^C in bash)
- blocking command + ctrl-\ ok
- blocking command + ctrl-D ok
- multiple ok
- no crash ok
- working? ok
- double quotes quote> not waiting if only one "
- echo "cat lol.c | cat > lol.c" ok
- anything except $ ok
- no crash ok
- working? ok
- simple quotes quote> not waiting if only one '
- empty argument '' blocked and crash if ctrl-C
- | > ok
- echo '$USER' ok
- no interpretation ok
- env ok
- export HELLO=hello ok
- export ok
- unset ok
- env ok
- cd ok
- multiple ok
- '.' '..' ok
- pwd ok
- multiple ok
- relative path ok
- cd ../../42/mini3/ ok
- ls, wc, awk ok
- unset PATH ok
- multiple path to check
- < > echo hola > test.txt cat < test.txt ok
- multiple and >> echo hola >> test.txt cat < test.txt ok
- multiple same redirect ok
- << cat <<END <<IN ok
- grep "hola" test.txt | wc -l ok
- cat test.txt | grep hola | more ok
- multiple ok
- ls filethatdoesntexist | grep hola | more ok
- ls -l | grep "\.txt" > try.txt ok
- command + ctr-C + enter ok
- history up down exec ok
- dsbksdgbksdghsd ok
- cat | cat | ls ok
- tar -czvf archive.tar.gz --exclude='*.log' --exclude='temp/' --exclude='backup/' ./test.txt ok
- echo $PATH ok
- check env variable ok
- echo "$PATH" to check
- check user ok
- echo "$USER" ok