Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • dfrancois/learning-bash
  • barriat/learning-bash
2 résultats
Afficher les modifications
Validations sur la source (2)
......@@ -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
......