notebook/IT/Linux/Shell.md

72 lines
891 B
Markdown
Raw Permalink Normal View History

2021-04-20 21:13:14 +00:00
# shell
2021-01-21 18:17:39 +00:00
2021-04-20 21:13:14 +00:00
## tips
2021-01-21 18:17:39 +00:00
- setter IFS au retour chariot
2021-04-20 21:13:14 +00:00
```IFS=$'\n'```
2021-01-21 18:17:39 +00:00
## boucle
2021-04-20 21:13:14 +00:00
```bash
2021-01-21 18:17:39 +00:00
for var in $variable
do
commande
done
```
## if
2021-04-20 21:13:14 +00:00
```bash
2021-01-21 18:17:39 +00:00
if [ test ]; then
echo "C'est vrai"
else
2021-04-20 21:13:14 +00:00
echo "c'est faux"
2021-01-21 18:17:39 +00:00
fi
```
### test
2021-04-20 21:13:14 +00:00
2021-01-21 18:17:39 +00:00
#### string
2021-04-20 21:13:14 +00:00
2021-01-21 18:17:39 +00:00
|test|def|
|----|---|
|$a = j$b|egale|
|$a != $b|different|
|-z $a|est vide|
|-n $a|est non vide|
#### int
|test|def|
|----|---|
|$a -eq $b|egale|
|$a -ne $b|non egale|
|$a -lt $b| < |
|$a -le $b| <= |
|$a -gt $b| >|
|$a -ge $b| >= |
2021-04-20 21:13:14 +00:00
#### file
2021-01-21 18:17:39 +00:00
|test|def|
|----|---|
|-e $a|exist|
|-d $a |is directory|
|-f $a | is file|
|-L $a | is symbolic link|
|-r -w -x | test permition|
|$a -nt $b| $a plus récent|
|$a -ot $b| $a plus vieux|
2021-01-26 17:33:44 +00:00
## Supprimer les Dossiers contenant 1 élement
2021-04-20 21:13:14 +00:00
```bash
2021-01-26 17:33:44 +00:00
IFS=$'\n';for i in $(ls) do  ✔  10022  18:29:32 
if [ $(ls $i|wc|awk '{print $1}') = 1 ]
then
rm -r $i
fi
```