3 ms·
> At least allow us to use names instead of numbers Many people probably think in terms of "fd 0" and "fd 1" instead of "standard in" and "standard out", but s
by xorcist 8mo ago
> At least allow us to use names instead of numbers
Many people probably think in terms of "fd 0" and "fd 1" instead of "standard in" and "standard out", but should you wish to use names at least on modern Linux/BSD systems do:
echo message >/dev/stdout
echo error_message >/dev/stderr
- vbezhenar 8mo agoI don't have macos right now but I think that it doesn't have these files. What's worse is that bash emulates these files so they might even somewhat work, but not in all situations. I distinctly remember issues with this command: install /dev/stdin file <<EOF something EOF
- mechanicalpulse 8mo agoI do and it does. $ ls -al /dev/std* lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stderr -> fd/2 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdin -> fd/0 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdout -> fd/1 $ ls -n /dev/fd/[012] crw--w---- 1 501 4 0x10000000 Feb 27 13:38 /dev/fd/0 crw--w---- 1 501 4 0x10000000 Feb 27 13:38 /dev/fd/1 crw--w---- 1 501 4 0x10000000 Feb 27 13:38 /dev/fd/2 $ uname -v Darwin Kernel Version 24.6.0: Mon Jan 19 22:00:55 PST 2026; root:xnu-11417.140.69.708.3~1/RELEASE_ARM64_T6000 $ sw_vers ProductName: macOS ProductVersion: 15.7.4 BuildVersion: 24G517 Lest you think it's some bashism that's wrapping ls, they exist regardless of shell: $ zsh -c 'ls -al /dev/std*' lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stderr -> fd/2 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdin -> fd/0 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdout -> fd/1 $ csh -c 'ls -al /dev/std*' lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stderr -> fd/2 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdin -> fd/0 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdout -> fd/1 $ tcsh -c 'ls -al /dev/std*' lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stderr -> fd/2 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdin -> fd/0 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdout -> fd/1 $ ksh -c 'ls -al /dev/std*' lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stderr -> fd/2 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdin -> fd/0 lr-xr-xr-x 1 root wheel 0 Feb 24 15:08 /dev/stdout -> fd/1 I tried the install example that you provided and it worked on macOS as well as Linux.
- burnt-resistor 8mo agoBash and zsh also allow, and modern Borne-compatible shells (sh) might too: echo >&2 error_message On Linux, /dev/std* requires the kernel to do file name resolution in the virtual file system because it could point to something nonstandard that isn't a symlink to something like /proc/self/fd/XX and then the kernel has to check that that should hopefully point to a special character device.