std: add cross platform null-device name (#11070)

# Description
We have meet a discord discussion about cross platform `null-device`:
https://discord.com/channels/601130461678272522/988303282931912704/1165966467095875624

I want the same feature too...And I think it's good enough to add it
into `nu-std`.

Different to https://github.com/nushell/nu_scripts/pull/649/files, I
think named it to `null-device`(the name comes from
[wiki](https://en.wikipedia.org/wiki/Null_device)) is better than
`null-stream`.
This commit is contained in:
WindSoilder 2023-11-17 21:49:07 +08:00 committed by GitHub
parent d1137cc700
commit 5063e01c12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -335,3 +335,16 @@ export def repeat [
1..$n | each { $item }
}
# return a null device file.
#
# # Examples
# run a command and ignore it's stderr output
# > cat xxx.txt e> (null-device)
export def null-device []: nothing -> path {
if ($nu.os-info.name | str downcase) == "windows" {
'\\.\NUL'
} else {
"/dev/null"
}
}