Skip to content
Extraits de code Groupes Projets
Valider be1d9d08 rédigé par Pierre-Yves Barriat's avatar Pierre-Yves Barriat
Parcourir les fichiers

Merge branch 'master' into 'master'

Split slide on variable exapnsion in two

See merge request !5
parents 2290002c 16f325a3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!5Split slide on variable exapnsion in two
......@@ -246,22 +246,29 @@ myvar=$( ls )
## String manipulation
Consider `string=abcABC123ABCabc` and `filename=myfile.txt`
Consider `string=abcABC123ABCabc`
* string length : `${#string}` is `15`
* substring extraction :
* `${string:7}` is `23ABCabc`
* `${string:7:3}` is `23A`
* `${string:(-4)}` or `${string: -4}` is `Cabc`
* substring removal from front :
* `${filename##myfile}` is `.txt`
* substring removal from back :
* `${filename%%.txt}` is `myfile`
<!--## Variable expansion
---
## String manipulation
Consider `filename=/var/log/messages.tar.gz`
* `${variable-default}` :
if `variable` is unset or null, the expansion of `default` is substituted-->
* substring removal from left :
* `${filename##/var}` is `/log/messages.tar.gz`
* substring removal from right :
* `${filename%%.gz}` is `/var/log/messages.tar`
You can use `*` to match all characters:
* `${filename%%.*}` is `/var/log/messages`
* `$(filename##*/)` is `messages.tar.gz`
---
......@@ -269,7 +276,7 @@ Consider `string=abcABC123ABCabc` and `filename=myfile.txt`
| Operator | Operation |
| ------------ | --------------- |
| `+` `-` `\*` `/` | addition, subtraction, multiply, divide |
| `+` `-` `\*` `/` | addition, subtraction, multiplication, division |
| `var++` | increase the variable var by 1 |
| `var--` | decrease the variable var by 1 |
| `%` | modulus (remainder after division) |
......@@ -309,7 +316,7 @@ a=$( expr 10 - 3 )
> it is the **preferred method**
-->
---
# Arithmetic
```bash
#!/bin/bash
......@@ -626,7 +633,7 @@ Try a simple example called `test_arg.sh` :
echo $1 $2 $4
echo $0
echo $#
echo $*
echo $@
```
```bash
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter