42 School - minishell project
sandoramix / 42-minishell Goto Github PK
View Code? Open in Web Editor NEW42 School - minishell project
License: The Unlicense
42 School - minishell project
License: The Unlicense
export
Questo commando mostra tutte le variabili d'ambiente e ha la possibilita' di aggiungerli/modificarli.
declare -x SGOINFRE="/nfs/homes/odudniak/sgoinfre"
declare -x SHELL="/bin/zsh"
declare -x SHLVL="2"
export <name>
: viene creata una variabile chiamata <name>
con il valore uguale a ""
(stringa vuota)
export test
test=''
export <name>=<value>
viene creata una variabile chiamata <name>
con il valore uguale a <value>
export test=foobar
test=foobar
0
Se si utilizza la gestione delle variabili d'ambiente tramite le liste, basterebbe implementare la ricerca del nodo in base alla chiave (<name>
) e modificare o aggiungere il nodo con quel valore <value>
Implementare il commando echo
echo
viene inserito \n
-n
echo -n ciao | cat -e
ciao%
echo -n "ciao\n" | cat -e
ciao$
Bisogna stare attenti a:
echo ciao mondo
ciao mondo
exit
Uscita dalla shell con uno statuscode
All'esecuzione del comando viene stampato "exit\n"
Se nessun argomento e' stato specificato, lo status code e' 0
se nessun commando e' stato eseguito, altrimenti e' lo statuscode dell'ultimo commando eseguito.
Se viene specificato un argomento n
la shell viene chiusa con lo status code n
specificato.
Se ci sono piu' argomenti, viene considerato il primo argomento come lo statuscode, oltre ad "exit\n" viene stampato un messaggio di errore ("bash: exit: too many arguments"), e la shell non si chiude.
The exit status shall be n, if specified. Otherwise, the value shall be
the exit value of the last command executed, or zero if no command was
executed. When exit is executed in a trap action, the last command is
considered to be the command that executed immediately preceding the
trap action.
env
<name>=<value>
USER=odudniak
DISPLAY=:0
SHLVL=2
NVM_CD_FLAGS=-q
PAGER=less
0
Se si utilizza la gestione delle variabili d'ambiente tramite le liste, basterebbe implementare la stampa di tutti i nodi nel formato corretto.
stdin
con readline
<
, >
, <<
], devono avere con un commando/argomento accanto a loro (forse?).e'cho' ''ciao'mondo'
> ["e'cho'", "''ciao'mondo'", NULL]
)char **
, un array/lista (da decidere, per un uso piu' semplice conviene usare gli array, per una prestazione migliore [meno allocazioni, ecc...] convengono le liste) di strutture, che avranno la stringa dell'argomento
e un tipo
con il valore:
DEFAULT
(0) - Una semplice stringa/argomentoTOKEN
(1) - Un token speciale (< > << ecc...).Quando si finisce il parsing dell'input (facendo vari check di validita', splittando, espandendo le variabili) nella lista di argomenti, tutti i commandi fatti finora dovranno essere modificati per adattarsi alla lista nuova creata in t_list *
al posto di char **
Implementare il commando pwd
All'esecuzione vengono ignorati tutti gli argomenti e viene stampato il path assoluto
della cartella corrente.
Le opzioni non si devono gestire.
Possibili soluzioni:
PWD
e OLDPWD
che:
OLDPWD
inizialmente non esiste ma viene aggiunto dopo il primo cd diverso da PWD
).PWD
, pwd
funziona ancora.t_var
per tenere al "sicuro" la directory corrente, che verra' inizializzata con $PWD
e ad ogni cambio di cartella verra' aggiornata.ChatGPT Suggestions:
The output of each command in the pipeline is connected to the input of the next command via a pipe.
The exit status of a pipeline is the exit status of the last command in the pipeline
Implementare il commando history
history
1 2024-04-20 15:04 cat nohup.out
2 2024-04-20 15:04 history
3 2024-04-20 15:04 ls
4 2024-04-20 15:04 ls -l
5 2024-04-20 15:04 ls -l | grep 4060
6 2024-04-20 15:04 ls -l | grep 4096
7 2024-04-20 15:04 echo "test"
8 2024-04-20 15:04 echo $TEST
9 2024-04-20 15:04 echo $USER
10 2024-04-20 15:05 history
11 2024-04-20 15:05 nano test
12 2024-04-20 15:05 cat test
13 2024-04-20 15:05 nano test
14 2024-04-20 15:05 history
15 2024-04-20 15:05 ls
16 2024-04-20 15:05 sl
17 2024-04-20 15:18 << EOF\nCIAO\nEOF
Forse si puo' semplificare togliendo le colonne della data e l'ora.
1 cat nohup.out
2 history
3 ls
4 ls -l
5 ls -l | grep 4060
6 ls -l | grep 4096
7 echo "test"
8 echo $TEST
9 echo $USER
10 history
11 nano test
12 cat test
13 nano test
14 history
15 ls
16 sl
unset
unset PWD nonexistent
0 All name operands were successfully unset.
Se si utilizza la gestione delle variabili d'ambiente tramite le liste, basterebbe implementare la ricerca e l'eliminazione di un nodo.
Bisogna implementare un while loop che ascolta l'input dell'utente per poi successivamente parsare ed eseguire i commandi.
N/A
Si potrebbe usare la readline
che gestisce anche la "history" degli ultimi commandi, usando gli directional arrows.
N/A
Visto che e' gia' possibile "parsare" (parzialmente) una stringa, possiamo integrare l'uso dei builtin con la funzione readline.
La procedura dovrebbe essere circa questa:
while
loop si usa readline
lst_addnew_tail
) in una lista nella struttura t_var mshell
che serve per la history
(#1) (che si dealloca solo in cleanup
). La chiave del nodo puo' rimanere NULL
cmd_parse_new
+ expand_and_clear
(vedi esempio qui) per ottenere la lista dei commandi/argomenti (per adesso si gestisce solo un commando).str_cmp
sul primo nodo). Se non e' un commando conosciuto si stampa <minishell prompt>: command not found: <valore del nodo>
sullo STD_ERR
.readline
P.s. il #if DEBUG == false
dentro main.c va tolto.
cd
The following exit values shall be returned:
0 The directory was successfully changed.
>0 An error occurred
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.