From b8fbf31ab5f401ed6ea24fadf6159557c2924921 Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Tue, 8 Apr 2025 15:58:33 -0400 Subject: [PATCH 1/2] Added some language comparisons --- book/special_variables.md | 111 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/book/special_variables.md b/book/special_variables.md index cd8c460baff..a4e2abfa571 100644 --- a/book/special_variables.md +++ b/book/special_variables.md @@ -47,6 +47,54 @@ The `$nu` constant is a record containing several useful values: `$env` is a special mutable variable containing the current environment variables. As with any process, the initial environment is inherited from the parent process which started `nu`. +::: details **_Comparison with other languages:_** + +::: tabs +@tab Nu + +```nu +# Set an environment variable +$env.VARNAME = "Content" + +# Access an environment variable +$env.VARNAME +# => Content + +# View all environment variables +$env +``` + +@tab Bash/POSIX + +````bash:no-line-numbers +# Set an environment variable +VARNAME="Content" +export VARNAME +# or +export VARNAME="Content" + +# Access an environment variable +echo $VARNAME +# => Content + +# View all environment variables +env + +@tab PowerShell + +```powershell +# Set an environment variable +$env:VARNAME = "Content" + +# Access an environment variable +$env:VARNAME +# => Content +```` + + + +::: + There are also several environment variables that Nushell uses for specific purposes: ### `$env.config` @@ -81,6 +129,40 @@ try { # => 2 ``` +::: details **_Comparison with other languages:_** + +::: tabs + +@tab Nu + +```nu +$env.LAST_EXIT_CODE +``` + +@tab Bash/POSIX + +```bash +$? +``` + +@tab PowerShell + +```powershell +# Code +$LASTEXITCODE + +# Successful - true or false +$? +``` + +@tab Perl + +```perl +$? >> 8 +``` + +::: + ### `env.CMD_DURATION_MS` The amount of time in milliseconds that the previous command took to run. @@ -103,6 +185,18 @@ the file resides. Note that this value is also available as a constant through: path self | path dirname ``` +::: details **_Comparison with other languages:_** + +::: tabs + +@tab PowerShell + +```powershell +$PSCommandPath +``` + +::: + ### `$env.PROCESS_PATH` When _executing a script_, this variable represents the name and relative path of the script. Unlike the two variables @@ -110,6 +204,23 @@ above, it is not present when sourcing a file or importing a module. Note: Also unlike the two variables above, the exact path (including symlinks) that was used to _invoke_ the file is returned. +::: details **_Comparison with other languages:_** + +::: tabs +@tab Nushell + +```nu +print $env.PROCESS_PATH +``` + +@tab Bash + +```bash +echo $0 +``` + +::: + ### `$env.NU_LIB_DIRS` A list of directories which will be searched when using the `source`, `use`, or `overlay use` commands. See also: From 10af72c7d0201f234374c9b2d9cd4e070ae4a85f Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Tue, 8 Apr 2025 16:07:38 -0400 Subject: [PATCH 2/2] Changed from dropdown details to embedded tip --- book/special_variables.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/book/special_variables.md b/book/special_variables.md index a4e2abfa571..d740f249a09 100644 --- a/book/special_variables.md +++ b/book/special_variables.md @@ -47,7 +47,7 @@ The `$nu` constant is a record containing several useful values: `$env` is a special mutable variable containing the current environment variables. As with any process, the initial environment is inherited from the parent process which started `nu`. -::: details **_Comparison with other languages:_** +::: tip In other shells and languages ... ::: tabs @tab Nu @@ -129,7 +129,7 @@ try { # => 2 ``` -::: details **_Comparison with other languages:_** +::: tip In other shells and languages ... ::: tabs @@ -185,10 +185,16 @@ the file resides. Note that this value is also available as a constant through: path self | path dirname ``` -::: details **_Comparison with other languages:_** +::: tip In other shells and languages ... ::: tabs +@tab Nu + +```nu +$env.FILE_PWD +``` + @tab PowerShell ```powershell @@ -204,7 +210,7 @@ above, it is not present when sourcing a file or importing a module. Note: Also unlike the two variables above, the exact path (including symlinks) that was used to _invoke_ the file is returned. -::: details **_Comparison with other languages:_** +::: tip In other shells and languages ... ::: tabs @tab Nushell