Timeline for How is "set -g" really different from "set" on fish shell?
Current License: CC BY-SA 4.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 5 at 11:50 | comment | added | ilkkachu | Wow, changing variables stored in persistent memory with the same command used for changing mere local variables seems a bit of a misfeature. Contrast with e.g. Python, where you need to explicitly declare globals used in a function with global foo to modify them. | |
| Mar 5 at 10:32 | comment | added | faho | That's correct, yeah. It's good practice everywhere to explicitly specify the scope the first time you use a variable in a function. This includes config.fish, where we often see set -x foo bar, which should be set -gx foo bar. | |
| Mar 5 at 9:37 | comment | added | Stéphane Chazelas | So set -g should always be used (in scripts at least) for global variables to remove the risk of a set var value changing a variable that happens to be universal (which could affect other scripts or interactive fish sessions by the same user)? | |
| Mar 5 at 9:34 | history | edited | Stéphane Chazelas | CC BY-SA 4.0 | added 83 characters in body |
| Mar 5 at 9:28 | vote | accept | jsx97 | ||
| Mar 5 at 9:23 | history | answered | faho | CC BY-SA 4.0 |