add: Supprimer une fonction shell avec unset

This commit is contained in:
Cédrix
2026-05-19 12:37:29 +02:00
parent 31d35302b6
commit ee2c43b985
5 changed files with 7909 additions and 2 deletions
+1 -1
View File
@@ -1 +1 @@
{"readable":true,"books":{"\/book\/esp":11,"\/book\/la-domotique-chez-soi":9,"\/book\/les-commandes-linux":9,"\/book\/linux-architecture-des-dossiers":8},"as":[{"asn":"","name":"LAN","country":"","hits":13163},{"asn":"14618","name":"AWS EC2 (us-east-1)","country":"US","hits":904},{"asn":"8075","name":"Cloud","country":"US","hits":877},{"asn":"32934","name":"Meta Platforms Ireland Limited","country":"US","hits":872},{"asn":"24940","name":"Hetzner","country":"FI","hits":399},{"asn":"16276","name":"OVH","country":"FR","hits":191},{"asn":"15169","name":"Google LLC","country":"US","hits":102},{"asn":"48230","name":"LLC MONOLITH.NET","country":"UA","hits":83},{"asn":"209366","name":"SEMrush CY LTD","country":"US","hits":80},{"asn":"50673","name":"Serveriuscustomer","country":"NL","hits":59},{"asn":"12322","name":"PROXAD-ADSL","country":"FR","hits":30},{"asn":"36352","name":"HostPapa","country":"US","hits":18},{"asn":"174","name":"Code 200, UAB","country":"FR","hits":12},{"asn":"18779","name":"EGIHosting","country":"US","hits":10},{"asn":"46261","name":"BraveWay","country":"US","hits":10},{"asn":"3209","name":"Vodafone Kabel Deutschland GmbH","country":"DE","hits":9},{"asn":"45102","name":"Alibaba.com LLC","country":"SG","hits":9},{"asn":"132203","name":"Tencent Cloud Computing (Beijing) Co., Ltd","country":"JP","hits":9},{"asn":"51207","name":"Free Mobile","country":"FR","hits":7},{"asn":"37054","name":"Telma Madagascar","country":"MG","hits":6},{"asn":"29695","name":"Lyse Tele AS","country":"NO","hits":5},{"asn":"41281","name":"KeFF Networks Ltd","country":"SE","hits":5},{"asn":"9443","name":"Vocus Retail","country":"AU","hits":5},{"asn":"16509","name":"Anthropic, PBC","country":"US","hits":4},{"asn":"396982","name":"Google Cloud (us-east5)","country":"US","hits":4},{"asn":"2119","name":"TELENOR-INTERNET","country":"NO","hits":4},{"asn":"58087","name":"Datalix","country":"DE","hits":4},{"asn":"15557","name":"SFR Infra","country":"FR","hits":3}]}
{"readable":true,"books":{"\/book\/esp":11,"\/book\/la-domotique-chez-soi":9,"\/book\/les-commandes-linux":9,"\/book\/linux-architecture-des-dossiers":8},"as":[{"asn":"","name":"LAN","country":"","hits":13177},{"asn":"32934","name":"Meta Platforms Ireland Limited","country":"US","hits":880},{"asn":"8075","name":"Cloud","country":"US","hits":878},{"asn":"14618","name":"AWS EC2 (us-east-1)","country":"US","hits":871},{"asn":"24940","name":"Hetzner","country":"FI","hits":399},{"asn":"16276","name":"OVH","country":"FR","hits":191},{"asn":"15169","name":"Google LLC","country":"US","hits":102},{"asn":"48230","name":"LLC MONOLITH.NET","country":"UA","hits":83},{"asn":"209366","name":"SEMrush CY LTD","country":"US","hits":80},{"asn":"50673","name":"Serveriuscustomer","country":"NL","hits":59},{"asn":"396982","name":"Google Cloud (us-central1)","country":"US","hits":38},{"asn":"12322","name":"PROXAD-ADSL","country":"FR","hits":30},{"asn":"36352","name":"HostPapa","country":"US","hits":18},{"asn":"13188","name":"CONTENT DELIVERY NETWORK LTD","country":"UA","hits":15},{"asn":"210743","name":"Babbar SAS","country":"FR","hits":13},{"asn":"174","name":"Code 200, UAB","country":"FR","hits":12},{"asn":"18779","name":"EGIHosting","country":"US","hits":10},{"asn":"46261","name":"BraveWay","country":"US","hits":10},{"asn":"3209","name":"Vodafone Kabel Deutschland GmbH","country":"DE","hits":9},{"asn":"132203","name":"Tencent Cloud Computing (Beijing) Co., Ltd","country":"JP","hits":9},{"asn":"45102","name":"Alibaba.com LLC","country":"SG","hits":7},{"asn":"51207","name":"Free Mobile","country":"FR","hits":7},{"asn":"37054","name":"Telma Madagascar","country":"MG","hits":6},{"asn":"29695","name":"Lyse Tele AS","country":"NO","hits":5},{"asn":"41281","name":"KeFF Networks Ltd","country":"SE","hits":5},{"asn":"9443","name":"Vocus Retail","country":"AU","hits":5},{"asn":"16509","name":"Anthropic, PBC","country":"US","hits":4},{"asn":"2119","name":"TELENOR-INTERNET","country":"NO","hits":4},{"asn":"58087","name":"Datalix","country":"DE","hits":4},{"asn":"15557","name":"SFR Infra","country":"FR","hits":3}]}
+1 -1
View File
@@ -1 +1 @@
{"fetched_at":1779067084,"version":"1.6.26"}
{"fetched_at":1779187033,"version":"1.6.26"}
@@ -0,0 +1,57 @@
# Supprimer une fonction shell avec `unset`
*Comment supprimer une fonction en Bash ? Comment effacer, retirer ou désenregistrer une fonction shell ? Comment annuler la définition d'une fonction Bash ? Quelle est la différence entre supprimer une variable et supprimer une fonction avec `unset` ? Pourquoi `man unset` ne fonctionne pas ?*
En Bash, la commande intégrée `unset` sert à supprimer des variables, mais aussi des **fonctions**. Pour cibler explicitement une fonction, on utilise l'option `-f` (pour *function*) :
```bash
unset -f foo
```
## Quand `-f` est-il vraiment nécessaire ?
D'après la documentation de Bash, sans option, `unset` essaie d'abord de supprimer une variable, puis se rabat sur une fonction si aucune variable de ce nom n'existe.
Autrement dit, **`-f` n'est indispensable que si une variable et une fonction portent le même nom**. Dans le cas contraire, un simple `unset foo` suffit.
## Exemple complet
```bash
# Définition d'une fonction
foo() { echo "bonjour"; }
foo
# → bonjour
# Suppression
unset -f foo
foo
# → bash: foo : commande introuvable
```
Et voici le cas où `-f` fait toute la différence :
```bash
foo="une variable"
foo() { echo "une fonction"; }
unset foo # supprime la variable
foo # → une fonction (la fonction existe toujours)
unset -f foo # supprime la fonction
```
## Consulter la documentation
`unset` étant une commande interne à Bash (*builtin*), elle n'a ni page `man unset` ni option `--help`. Sa documentation se consulte avec :
```bash
help unset
```
## À retenir
- `unset -f nom` supprime explicitement une fonction.
- `unset nom` suffit si aucune variable ne porte ce nom.
- Pour la doc d'un builtin Bash : `help <commande>`, pas `man`.
@@ -0,0 +1,20 @@
{
"uuid": "7a2f79a2-768c-4682-8640-1888f1ad5a9d",
"slug": "supprimer-une-fonction-shell-avec-unset",
"title": "Supprimer une fonction shell avec `unset`",
"author": "cedric@abonnel.fr",
"published": false,
"featured": false,
"published_at": "2026-05-19 10:37:27",
"created_at": "2026-05-19 10:37:27",
"updated_at": "2026-05-19 10:37:27",
"revisions": [],
"cover": "",
"files_meta": [],
"external_links": [],
"seo_title": "",
"seo_description": "",
"og_image": "",
"category": "",
"tags": []
}
File diff suppressed because it is too large Load Diff