MaJ du 04-02-2021

This commit is contained in:
2021-02-04 09:55:26 +01:00
parent 84b4e1a85d
commit fb07a20b0c
56 changed files with 4962 additions and 95 deletions

View File

@@ -32,6 +32,12 @@ fi
if [ "$choice" == "72" ]; then echo "sphp 72"; elif [ "$choice" == "73" ]; then echo "sphp 73"; fi
```
### Ternaire
```bash
[ "$nb" -gt 1 ] && echo -e "condition ok" || echo -e "condition nok"
```
### if imbriqué
@@ -86,6 +92,22 @@ fi
#### -fichier
Si le répertoire *<u>directory</u>* existe
```bash
if [ -d directory ]; then
if [ -d ~/.kde ]; then
```
Si le fichier *<u>regularfile</u> (ni un blockspecialfile, ni un characterspecialfile, ni un directory)* existe
```bash
if [ -f regularfile ]; then
if [ -f ~/.bashrc ]; then
```
Si le fichier *<u>existingfile</u>* existe
```bash
@@ -112,22 +134,6 @@ if [ -c characterspecialfile ]; then
if [ -c /dev/dsp ]; then
```
Si le répertoire *<u>directory</u>* existe
```bash
if [ -d directory ]; then
if [ -d ~/.kde ]; then
```
Si le fichier *<u>regularfile</u> (ni un blockspecialfile, ni un characterspecialfile, ni un directory)* existe
```bash
if [ -f regularfile ]; then
if [ -f ~/.bashrc ]; then
```
Si le fichier *<u>sgidfile</u> (set-group-ID)* existe
```bash
@@ -445,3 +451,24 @@ Si NUM 1 est <u>inférieur ou égal à</u> (( NUM1 <= NUM2 ))
if (( NUM1 <= NUM2 )); then
```
#### -test si la variable est un entier/decimal/chaine:
```bash
#!/bin/bash
read -p "Type a number or a string: " input
if [[ $input =~ ^[+-]?[0-9]+$ ]]; then
echo "Input is an integer."
elif [[ $input =~ ^[+-]?[0-9]+\.$ ]]; then
echo "Input is a string."
elif [[ $input =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
echo "Input is a float."
else
echo "Input is a string."
fi
```