Closed FernandaMatt closed 1 year ago
Built-int commands are nothing but commands or functions, called from a shell, that are executed directly in the shell itself. The bash shell executes the command directly, without invoking another program. You can view information for Bash built-ins with help command, which is also a built-in command. There are different types of built-in commands in the different shells.
bash defines the following built-in commands: :, ., [, alias, bg, bind, break, builtin, case, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, if, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, unalias, unset, until, wait, while.
🇧🇷
Os comandos built-in de uma shell, ou seja, os comandos "construídos dentro" em uma tradução literal, são nada mais nada menos que aqueles comandos que já vem embutidos e que são executados pela própria shell. Ou seja, a shell executa o comando por conta própria, sem invocar nenhum outro programa. Os built-ins de uma shell podem ser exibidos com o comando help
, que, por sua vez, também é um comando built-in. Existem diferentes tipos de built-ins nas diferentes shells.
O bash estabelece os seguintes comandos built-in: :, ., [, alias, bg, bind, break, builtin, case, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, if, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, unalias, unset, until, wait, while.
🇺🇸
Use:
pwd
The pwd function prints the current working directory path, starting from the /root
. It can be used to locate yourself in a Linux file system, or to obtain the working directory in a bash/shell script.
🇧🇷
A função pwd imprime o caminho do diretório atual partindo da raíz `/root. O comando pode ser usado para se localizar em um sistema linux, ou para obter o diretório atual em um bash/shell script.
Ex.:
bash-3.2$ cd
bash-3.2$ pwd
/Users/fcaetano
bash-3.2$ cd projects/mini-bash/
bash-3.2$ pwd
/Users/fcaetano/projects/mini-bash
🇺🇸
To implement a pwd()
function in C, like the one from bash, we can use the getcwd
function from the <unistd.h>
library.
🇧🇷
Para implementar a função pwd()
do bash em C, podemos utilizar a função getcwd
da biblioteca <unistd.h>
.
🇺🇸
Use:
echo [-n] [arg …]
The echo function output the arguments passed, separated by spaces and terminated with a newline. If the -n option is given, the trailing newline is supressed.
🇧🇷
A função echo imprime os argumentos passados separados por espaços e terminados em uma quebra de linha. Se a opção -n for utilizada, a quebra de linha ao final é suprimida.
Ex.:
feffa:mini-bash$ echo test
test
feffa:mini-bash$ echo test multiple arguments
test multiple arguments
feffa:mini-bash$ echo test multiple arguments "and string arguments"
test multiple arguments and string arguments
feffa:mini-bash$ echo -n test with -n flag
test with -n flagfeffa:mini-bash$
feffa:mini-bash$ echo
feffa:mini-bash$ echo -n
🇺🇸
Use:
cd [directory]
The cd
function change the current workind directory to [directory]. If directory is not supplied, the value of the HOME shell variable is used.
To implement a cd
function in C, like the one from bash, the chdir()
function from the
🇧🇷
A função cd
muda o diretório atual para [directory]. Se o diretório não é fornecido, então o valor da variável HOME é utilizado.
Para implementar a função cd
, como a disponível no bash, utilizou-se a função chdir()
da biblioteca
Extra: original bash function.
🇺🇸
If the shell variable CDPATH exists, it is used as a search path: each directory name in CDPATH is searched for directory, with alternative directory names in CDPATH separated by a colon (‘:’). If directory begins with a slash, CDPATH is not used. This functionality was not implement in this shell.
🇧🇷
Se a variável CDPATH existe, então ela é usada para procurar pelo caminho fornecido: [directory] é procurado em cada diretório de CDPATH, sendo que os diferentes diretórios em CDPATH são separados por dois pontos (':'). Se o diretório passado inicializar com uma barra, então CDPATH não é utilizada. Essa funcionalidade não foi implementada na minishell.
Ex.:
feffa:test$ ls -R
.:
diretory
./diretory:
sub_directory
./diretory/sub_directory:
feffa:test$ cd sub_directory
bash: cd: sub_directory: No such file or directory
feffa:test$ cd diretory/
feffa:diretory$ pwd
/home/feffa/test/diretory
feffa:diretory$ cd ../
feffa:test$ cd sub_directory
bash: cd: sub_directory: No such file or directory
feffa:test$ export CDPATH=".:/home/feffa/test/diretory:"
feffa:test$ cd sub_directory/
/home/feffa/test/diretory/sub_directory
feffa:sub_directory$ unset CDPATH
feffa:sub_directory$ cd sub_directory/
bash: cd: sub_directory/: No such file or directory
Funções a serem implementadas:
echo
with option-n
(Fernanda)cd
with only a relative or absolute path (Fernanda)pwd
with no options (Fernanda)export
with no options (Michael)unset
with no options (Michael)env
with no options or arguments (Michael)exit
with no options (Michael)