-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cookbook getenv\n\nRecreate PR #2383
- Loading branch information
Cuihtlauac ALVARADO
committed
May 13, 2024
1 parent
2f496c7
commit 7be3088
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
packages: [] | ||
discussion: | | ||
- **Understanding `Sys.getenv` and `Sys.getenv_opt`:** Both `Sys.getenv` and `Sys.getenv_opt` functions take a environment variable name and return its value. `Sys.getenv` returns directly the value, but raises a `Not_found` exception if the variable doesn't exist. `Sys.getenv_opt` returns an `option` type: `Some value` if the variable exists and `None` if not. | ||
--- | ||
|
||
let path = Sys.getenv "PATH" | ||
let () = | ||
Printf.printf "The path is %s\n" path | ||
|
||
let () = | ||
match Sys.getenv_opt "OPAM_SWITCH_PREFIX" with | ||
| Some p -> | ||
Printf.printf "The Opam switch prefix is %s\n" p | ||
| None -> | ||
print_string "The Opam switch prefix is not set.\n" |