From 0a9f23f3e727c974a81a736cd747ce13ca8b7b9b Mon Sep 17 00:00:00 2001 From: Jacques Dainat <jacques.dainat@ird.fr> Date: Wed, 28 Feb 2024 09:45:59 +0100 Subject: [PATCH] update --- docs/pages/bash/bash-3-navigating.md | 2 +- docs/pages/bash/bash-5-special_characters.md | 10 +-- docs/pages/bash/bash-6-path.md | 4 +- docs/pages/bash/bash-7-commands.md | 86 ++++++++++++++++++-- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/docs/pages/bash/bash-3-navigating.md b/docs/pages/bash/bash-3-navigating.md index 7c7e173..1429494 100644 --- a/docs/pages/bash/bash-3-navigating.md +++ b/docs/pages/bash/bash-3-navigating.md @@ -12,7 +12,7 @@ First copy and paste this command to execute it. No worries not need to understa course={{extra.working_directory}} mkdir -p ~/$course/script mkdir -p ~/$course/data -touch ~/$course/README +echo "Welcome to the {{extra.working_directory}} course" > ~/$course/README echo "echo hello" > ~/$course/script/script1.sh echo "ATGC" > ~/$course/data/data1.fa touch ~/$course/data/dataA.fastq diff --git a/docs/pages/bash/bash-5-special_characters.md b/docs/pages/bash/bash-5-special_characters.md index 361bf99..d85b959 100644 --- a/docs/pages/bash/bash-5-special_characters.md +++ b/docs/pages/bash/bash-5-special_characters.md @@ -84,11 +84,11 @@ We can observe in the variable case, it's value is printed, while it was not the In the second example the litteral value `(` is printed. ### Escaping - -Not from the room... -In bash it exists a special character allowing to escape a special character. {: style="height:100px"} -You can avoid a special character to be interpreted as "special" by adding a backslash `\`. - +{: style="height:100px" align=right} +Not from the room... +In bash it exists a *special character allowing to escape a special character*. +You can avoid a special character to be interpreted as "special" by adding a backslash `\`. + Let's give a try to make it clearer: ```bash diff --git a/docs/pages/bash/bash-6-path.md b/docs/pages/bash/bash-6-path.md index ea378d5..69800f0 100644 --- a/docs/pages/bash/bash-6-path.md +++ b/docs/pages/bash/bash-6-path.md @@ -1,6 +1,6 @@ # The PATH variable -The PATH environment variable (variable available by all shells) is very important, it specifies the directories to be searched to find a command absent from bash itself. +The **PATH** environment variable (variable available by all shells) is very important, it specifies the directories to be searched to find a command absent from bash itself. When calling a tool, Bash will first look among commands shipped with him, then look at your current directory, and finally will look in order in all directories listed un the PATH variable. It is how your computer access tools. There is no magic. The computer is just following some simple rules. If you call a tool unknown by Bash and not part of any path listed in $PATH, there is no way for your computer to guess where it is and will tell you `command not found`. @@ -34,6 +34,6 @@ The paths are listed using the `:` separator. !!! Success "Quick recap" In this section we've learned: - - the PATH variable + - the PATH variable - the logic how a command or a tool is found on the computer diff --git a/docs/pages/bash/bash-7-commands.md b/docs/pages/bash/bash-7-commands.md index c700d19..9308aeb 100644 --- a/docs/pages/bash/bash-7-commands.md +++ b/docs/pages/bash/bash-7-commands.md @@ -1,15 +1,89 @@ # Commands +Bash 4.3 comes with 58 embeded commands: -## Commands +``` + 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. +``` -### -1 commands, 2 coomadns etc.. pipe +They are built-in for performance reasons. +There are many more commands available on your machine. Unix machines have several hundreds of different commands. +A good place to look at them is ([http://ss64.com/mac](http://ss64.com/mac) or [http://ss64.com/bash](http://ss64.com/bash). -save command results in a variavle -var=$(pwd) +**No worries! As most of people we only need to use a very small subset of those commands.** -### I/O of commmands +## How commands works + +```bash +command [ -option ] [ arguments ] +``` + + * [ ] means this is optional (e.g. `ls` vs `ls -l`) + * **Option** only modify the behavior of the command. It starts with `-` (or `--` for long option) + * **Argument** controls the output of the command. It specifies a target for the command. + +It is possible to execute several commands in one line using **;** in between commands: + +```bash +command1 ; command2 +``` + +It is possible to save the output of a command in a variable: + +```bash +var=$(command) +``` + +### Input/Output of commmands + +Commands can take different arguments: + +** Nothing ** +```bash +ls +``` + +** String ** +```bash +echo hello world +``` + +** File ** +```bash +cat file_input +``` + +** A stream ** +What is a stream? + explanation here + +```bash +cat file_input | tr a-z A-Z +``` + +It is possible to send the output (STDOUT) of a command as input (STDIN) of another using **|**: + +```bash +command1 | command2 +``` + +It is possible to save/send the output of a command in a file: +```bash +# overwrite file if already exists +command > file +# append file if already exists +command >> file +``` + +/!\\ commmands that take an input either from a **file** of from **STDIN**: grep, sed, cat, head, sort, wc, etc. +/!\\ commmands that **never read STDIN**: ls, cp, mv, date, who, pwd, echo, cd, etc. +/!\\ commmands that **read only STDIN**: tr + ### Command pipes -- GitLab