MaJ du 04-02-2021
This commit is contained in:
@@ -125,6 +125,14 @@ Cabc
|
||||
|
||||
$ echo ${string:(-4)}
|
||||
Cabc
|
||||
|
||||
$ echo -n $string | tail -c 4
|
||||
|
||||
# Filename / extension
|
||||
|
||||
filename=$(basename "$fullfile")
|
||||
extension="${filename##*.}"
|
||||
filename="${filename%.*}"
|
||||
```
|
||||
|
||||
|
||||
@@ -158,3 +166,75 @@ ABC123ABC
|
||||
|
||||
http://tldp.org/LDP/abs/html/string-manipulation.html
|
||||
|
||||
#### Majuscule / Capitalize:
|
||||
|
||||
```bash
|
||||
string=bonjour
|
||||
|
||||
# 1ere lettre en majuscule (Bash 4)
|
||||
echo ${string^}
|
||||
Bonjour
|
||||
|
||||
# Met en majuscule toute la chaine (Bash 4)
|
||||
|
||||
echo ${string^^}
|
||||
BONJOUR
|
||||
|
||||
echo $string | tr '[:lower:]' '[:upper:]'
|
||||
echo $string | tr '[a-z]' '[A-Z]'
|
||||
BONJOUR
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Parcourrir une variable multi-ligne:
|
||||
|
||||
```bash
|
||||
dependencies=$(echo "CairoSVG,setuptools" | xargs pipdeptree -r -p )
|
||||
```
|
||||
|
||||
```bash
|
||||
while IFS= read -r line; do
|
||||
|
||||
echo "${line}"
|
||||
|
||||
done <<< "$dependencies"
|
||||
|
||||
# IFS= requis pour afficher les espaces en début de ligne
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### Regex:
|
||||
|
||||
[[ STRING =~ REGEX ]]
|
||||
|
||||
Chaine commençant par:
|
||||
|
||||
```bash
|
||||
# String est une url ?
|
||||
|
||||
if [[ $string =~ ^http ]]
|
||||
```
|
||||
|
||||
Chaine se terminant par:
|
||||
|
||||
```bash
|
||||
# String est un fichier .mp3 ?
|
||||
|
||||
if [[ $string =~ .mp3$ ]]
|
||||
```
|
||||
|
||||
Adresse IP:
|
||||
|
||||
```bash
|
||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
```
|
||||
|
||||
Email:
|
||||
|
||||
```bash
|
||||
if [[ "$email" =~ "^[A-Za-z0-9._%+-]+<b>@</b>[A-Za-z0-9.-]+<b>\.</b>[A-Za-z]{2,4}$" ]]
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user