Files
gosh/dup_linux.go
Florian WaltherandClaude Opus 5.5 1f507f6562 add parameter expansion, arithmetic, set -e/-x/pipefail, trap, eval, exec
- ${#v}, ${v#p} ${v##p} ${v%p} ${v%%p}, ${v/p/r} ${v//p/r} ${v/#p/r}
  ${v/%p/r}, ${v:off:len}, ${v-w} ${v:=w} ${v:+w} ${v:?msg}; nested ${}
- arithmetic expansion $((...)) with the C operators, ** and assignments
- set -e, set -x, set -o pipefail (also as gosh options, passed on to
  subshells); set shows variables, set -o the options
- trap for EXIT and signals; scripts with an EXIT trap run it on
  SIGINT/SIGTERM/SIGHUP too
- eval, exec (also exec > file without a command), $!, wait pid

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 21:15:24 +02:00

17 lines
298 B
Go

package main
import (
"os"
"golang.org/x/sys/unix"
)
// dupTo makes file descriptor fd refer to f (dup2; linux/arm64 only has
// dup3).
func dupTo(f *os.File, fd int) error {
if int(f.Fd()) == fd {
return nil // dup3 fails for the same descriptor
}
return unix.Dup3(int(f.Fd()), fd, 0)
}