03-04-2020

This commit is contained in:
2020-04-03 08:23:52 +02:00
parent 40622b4d98
commit 4e729b80c6
6 changed files with 286 additions and 78 deletions

View File

@@ -24,96 +24,47 @@ declare -i i; i+=1 user 0m0.492s
i=0; i=$(expr $i + 1) user 0m5.464s
```
#### [Chaine de caractères:](strings.md)
##### Concaténer une chaine:
```bash
upd+="$name "
```
#### Trim une chaine:
##### 1. sed
#### Chemins:
Répertoire courant (pwd) , nom du script (basename), répertoire du script (dirname)
```bash
$ var=" Une chaine entourée d'espaces "
~/Documents/go $ nano chemins.sh
$ echo "Fluctuat nec $var mergitur"
Fluctuat nec Une chaine entourée d'espaces mergitur
#!/usr/local/bin/bash
echo "Le script exécuté a comme basename `basename "$0"`, dirname `dirname "$0"`"
echo "Le répertoire courant est `pwd`"
# supprimer les espaces en fin de chaine: sed 's/ *$//g'`
$ var=`echo $var | sed 's/ *$//g'`
~/Documents/go $ ./chemins.sh
Le script exécuté a comme basename chemins.sh, dirname .
Le répertoire courant est /Users/bruno/Documents/go
$ echo "Fluctuat nec $var mergitur"
Fluctuat nec Une chaine entourée d'espaces mergitur
cd ..
~/Documentsr $ go/chemins.sh
Le script exécuté a comme basename chemins.sh, dirname go
Le répertoire courant est /Users/bruno/Documents
# supprimer les espaces en début de chaine: sed 's/^ *//g'`
$ var=`echo $var | sed 's/^ *//g'`
$ echo "Fluctuat nec $var mergitur"
Fluctuat nec Une chaine entourée d'espaces mergitur
# supprimer les espaces en début et fin de chaine:
$ var=" Une chaine entourée d'espaces "
$ echo "$var" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//'
Une chaine entourée d'espaces
```
##### 2. awk
```bash
$ echo "${var}"
Une chaine entourée d'espaces
$ echo "${var}" | awk '{gsub(/^[ \t]+/,""); print $0, " fin" }'
Une chaine entourée d'espaces fin
$ echo "${var}" | awk '{gsub(/[ \t]+$/,""); print $0, " fin" }'
Une chaine entourée d'espaces fin
$ echo "${var}" | awk '{gsub(/^[ \t]+| [ \t]+$/,""); print $0, " fin" }'
Une chaine entourée d'espaces fin
```
##### 3. xargs
```bash
$ var=" Une chaine entourée d espaces "
$ echo "$var" | xargs
Une chaine entourée d espaces
$ echo " Une chaine entourée d espaces " | xargs
Une chaine entourée d espaces
# erreur si la chaine contient un apostrophe
$ echo " Une chaine entourée d'espaces " | xargs
xargs: unterminated quote
# dans ce cas, on utilise xargs -0
$ echo " Une chaine entourée d'espaces " | xargs -0
Une chaine entourée d'espaces
cd ~
~ $ /Users/bruno/Documents/go/chemins.sh
Le script exécuté a comme basename chemins.sh, dirname /Users/bruno/Documents/go
Le répertoire courant est /Users/bruno
```
#### Longueur d'une chaine:
```bash
$ echo -n "Longueur de la chaine:" | wc -c
22
$ echo "Longueur de la chaine:" | awk '{print length}'
22
$ var="Longueur de la chaine:"
$ echo ${#var}
22
```
#### [Tableaux:](tableaux.md)
Déclarer un tableau associatif:
@@ -123,6 +74,8 @@ declare -a do_not_update=('')
#### Commandes:
##### Test si une commande existe:
```bash

150
docs/Divers/bash/strings.md Normal file
View File

@@ -0,0 +1,150 @@
# Chaine de caractères:
##### Concaténer une chaine:
```bash
upd+="$name "
```
##### Trim une chaine:
1. sed
```bash
$ var=" Une chaine entourée d'espaces "
$ echo "Fluctuat nec $var mergitur"
Fluctuat nec Une chaine entourée d'espaces mergitur
# supprimer les espaces en fin de chaine: sed 's/ *$//g'`
$ var=`echo $var | sed 's/ *$//g'`
$ echo "Fluctuat nec $var mergitur"
Fluctuat nec Une chaine entourée d'espaces mergitur
# supprimer les espaces en début de chaine: sed 's/^ *//g'`
$ var=`echo $var | sed 's/^ *//g'`
$ echo "Fluctuat nec $var mergitur"
Fluctuat nec Une chaine entourée d'espaces mergitur
# supprimer les espaces en début et fin de chaine:
$ var=" Une chaine entourée d'espaces "
$ echo "$var" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//'
Une chaine entourée d'espaces
```
2. awk
```bash
$ echo "${var}"
Une chaine entourée d'espaces
$ echo "${var}" | awk '{gsub(/^[ \t]+/,""); print $0, " fin" }'
Une chaine entourée d'espaces fin
$ echo "${var}" | awk '{gsub(/[ \t]+$/,""); print $0, " fin" }'
Une chaine entourée d'espaces fin
$ echo "${var}" | awk '{gsub(/^[ \t]+| [ \t]+$/,""); print $0, " fin" }'
Une chaine entourée d'espaces fin
```
3. xargs
```bash
$ var=" Une chaine entourée d espaces "
$ echo "$var" | xargs
Une chaine entourée d espaces
$ echo " Une chaine entourée d espaces " | xargs
Une chaine entourée d espaces
# erreur si la chaine contient un apostrophe
$ echo " Une chaine entourée d'espaces " | xargs
xargs: unterminated quote
# dans ce cas, on utilise xargs -0
$ echo " Une chaine entourée d'espaces " | xargs -0
Une chaine entourée d'espaces
```
##### Longueur d'une chaine:
```bash
$ echo -n "Longueur de la chaine:" | wc -c
22
$ echo "Longueur de la chaine:" | awk '{print length}'
22
$ var="Longueur de la chaine:"
$ echo ${#var}
22
```
##### Sous-chaine:
```bash
$ string=abcABC123ABCabc
$ echo ${string:0}
abcABC123ABCabc
$ echo ${string:1}
bcABC123ABCabc
$ echo ${string:7}
23ABCabc
$ echo ${string:7:3}
23A
$ echo ${stringZ: -4} # Notez l'espace
Cabc
$ echo ${string:(-4)}
Cabc
```
Remplacement de sous-chaine:
```bash
$ string=abcABC123ABCabc
$ echo ${string/abc/xyz} # Remplace la 1ere sous-chaine 'abc' par 'xyz'.
xyzABC123ABCabc
$ echo ${string//abc/xyz} # Remplace toutes les sous-chaine 'abc' par 'xyz'.
xyzABC123ABCxyz
match=abc
repl=000
echo ${string/$match/$repl}
000ABC123ABCabc
echo ${string//$match/$repl}
000ABC123ABC000
echo ${stringZ/abc} # Supprime la 1ere sous-chaine 'abc'
ABC123ABCabc
echo ${stringZ//abc} # Supprime toutes les sous-chaine 'abc'
ABC123ABC
```
http://tldp.org/LDP/abs/html/string-manipulation.html

View File

@@ -59,10 +59,15 @@ Laffichage de lensemble dun tableau se fait avec la syntaxe `${montable
$ declare -a tableau_indi=( "un" "deux" "trois" "quatre" )
$ echo ${tableau_indi[@]}
un deux trois quatre
$ echo ${tableau_indi[2]}
deux
$ declare -A tableau_asso=( ['chene']="gland" ['erable']="sirop" ['hetre']="faine" )
$ echo ${tableau_asso[@]}
gland faine sirop
$ echo ${tableau_asso[erable]}
sirop
```
@@ -80,11 +85,13 @@ un deux trois quatre # !!! normalement 'un'
$ declare -A tableau_asso=( ['chene']="gland" ['erable']="sirop" ['hetre']="faine" )
$ echo ${tableau_asso["erable"]}
# !!!! rien sur zsh !!!!
$ echo ${tableau_asso[erable]}
sirop
```
Ajouter un élément:
#### Ajouter un élément:
```bash
ARRAY=()
@@ -109,7 +116,7 @@ Il nest pas possible de créer un tableau associatif en lui assignant un él
Afficher la liste des clés:
#### Afficher la liste des clés:
```bash
$ declare -a tableau_indi=( "un" "deux" "trois" "quatre" )
@@ -125,7 +132,7 @@ zsh: event not found: tableau_asso[@] # !!!
Obtenir la taille d'un tableau:
#### Obtenir la taille d'un tableau:
```bash
$ declare -a tableau_indi=( "un" "deux" "trois" "quatre" )
@@ -139,7 +146,7 @@ $ echo ${#tableau_asso[@]}
Supprimer un élément:
#### Supprimer un élément:
```bash
$ declare -a tableau_indi=( "un" "deux" "trois" "quatre" )
@@ -174,7 +181,7 @@ gland faine sirop
Supprimer un tableau entier:
#### Supprimer un tableau entier:
```bash
$ declare -a tableau_indi=( "un" "deux" "trois" "quatre" )

View File

@@ -51,6 +51,45 @@ updating: https://github.com/zdharma/fast-syntax-highlighting
updating: https://github.com/zsh-users/zsh-autosuggestions
```
Si erreur pendant la mise-à-jour:
```bash
$ antibody update
Updating all bundles in /Users/bruno/Library/Caches/antibody...
antibody: updating: https://github.com/zsh-users/zsh-history-substring-search
antibody: updating: https://github.com/sindresorhus/pure
antibody: updating: https://github.com/mafredri/zsh-async
antibody: updating: https://github.com/zsh-users/zsh-autosuggestions
antibody: updating: https://github.com/zsh-users/zsh-completions
antibody: updating: https://github.com/marzocchi/zsh-notify
antibody: updating: https://github.com/zdharma/fast-syntax-highlighting
antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zdharma-SLASH-fast-syntax-highlighting
antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-marzocchi-SLASH-zsh-notify
antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions
antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-sindresorhus-SLASH-pure
antibody: git update failed for /Users/bruno/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-completions
antibody: error: failed to update: object not found
```
il faut vider le cache:
```bash
~/Library/Caches/antibody
rm -rf https-COLON*
# ou
rm -rf "$(antibody home)"
```
puis les recharger:
```bash
$ antibody bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh
```
##### Liste des plugins/thèmes installés:
@@ -86,3 +125,16 @@ drwxr-xr-x 12 bruno staff 384 7 jui 18:08 https-COLON--SLASH--SLASH-github
drwxr-xr-x 7 bruno staff 224 7 jui 18:01 https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-history-substring-search
```
# Z plugin (jump around)
https://github.com/rupa/z
Copier le script `z.sh` dans `/usr/local/etc/profile.d/`
puis ajouter `. /usr/local/etc/profile.d/z.sh` au fichier .zshrc

View File

@@ -0,0 +1,40 @@
# Hackintosh
[Darkwake - Powernap - Power Management - Sleep & wake (Catalina)](https://www.insanelymac.com/forum/topic/342002-darkwake-on-macos-catalina-boot-args-darkwake8-darkwake10-are-obsolete/)
#### Darkwake:
Par défaut Catalina 10.5.1: `Darkwake = 3`
#### Power Management:
Réglages courants:
```bash
pmset -g
```
Réglages recommandés:
```bash
sudo pmset -a hibernatemode 0
sudo pmset -a proximitywake 0
sudo pmset -a powernap 0
```
Voir ce qui empêche la mise en veille:
```bash
pmset -g assertions
```
Historique:
```bash
pmset -g log|grep -e " Sleep " -e " Wake "
```

View File

@@ -30,6 +30,12 @@ Changer le port ssh (22 par défaut) sur macOS:
#### SeKey
https://github.com/sekey/sekey
**12.6.1 HTTPS vs SSH**
If you think you have SSH set up correctly and yet you are still challenged for credentials, consider this: for the repo in question, have you possibly set up GitHub, probably called origin, as an HTTPS remote, instead of SSH?