--- title: Know which grep, sed, date and ls a script runs: illumos /usr/bin, /usr/xpg4/bin, or GNU area: shell impact: HIGH tags: [shell, posix, xpg4, xpg6, gnu, sed, grep, date, ls, ksh93, path, porting] verified: 2026-11-04 --- # Know which grep, sed, date and ls a script runs: illumos /usr/bin, /usr/xpg4/bin, or GNU On Solnix `/usr/bin/grep`, `sed`, `date` and `ls` are the illumos tools, not GNU. `/usr/xpg4/bin` and `/usr/xpg6/bin` hold the standards-conforming variants, and the GNU tools are separate packages that are not on PATH by default. A Linux script that uses GNU flags fails, or worse, runs and does something else (`grep -b`, `ls -v`). **Antipattern** ```sh grep -P '\d+' app.log; grep -m1 err app.log # /usr/bin/grep has no -P and no -m grep -b needle file # runs, but prints a block number, not a byte offset sed --in-place -z 's/a/b/' f # /usr/bin/sed has no long options and no -z sed -i '' 's/a/b/' f # FreeBSD form; here the suffix is attached (-i.bak) date -d '1 day ago' +%Y-%m-%d # /usr/bin/date has no -d (and no -s, no -I) ls -v # runs, but gives a long listing, not a version sort PATH=/usr/gnu/bin:$PATH # OpenIndiana habit: a bare Solnix system has no /usr/gnu ``` **The Solnix way** ```sh whence -a grep sed date ls # ksh93, the default login shell: all interpretations of each name (whence -a), not only the PATH matches ls -l "$(command -v grep)" # the link target is the store path of the package that ships it head -1 ./configure # the #! picks the shell: /usr/xpg4/bin/sh is the same ksh93 as /bin/sh /usr/xpg4/bin/date -u +%C # a variant by absolute path: here %C is the century, not the date and time date -r 1700000000 +%Y-%m-%d # a known epoch time, without GNU -d: -r takes seconds or a file name sed 's/a/b/' f > f.tmp && mv f.tmp f # portable in-place edit; sed -i.bak also works on /usr/bin/sed grep -E 'a|b' f # stick to -E -F -i -v -c -l -n -q -e -f ``` ```nix # a service whose method needs GNU tools: put them by store path ahead of /usr/bin (method_environment) smf.services.myjob.environment.PATH = "${pkgs.solnix.gnugrep}/bin:${pkgs.solnix.gnused}/bin:/usr/bin:/usr/sbin"; ``` The login PATH Solnix generates starts with `/run/wrappers/bin` and the profiles in this order (`environment.profiles`: the system's `/run/current-system/sw`, `~/.nix-profile`, `/nix/var/nix/profiles/default`), keeps the PATH the shell inherited (normally with `/usr/bin`), then appends whichever of `/nix-tools/bin:/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/usr/ccs/bin` is not already on it; it adds no `/usr/xpg4/bin` or `/usr/xpg6/bin`. `/usr/bin` links to the system profile, where `environment.systemPackages` win name clashes with the illumos world: adding gnugrep there (as opt-in `extra-userland.nix` does) replaces `/usr/bin/grep` for every script. **The illumos way** (OpenIndiana, OmniOS, SmartOS) ```sh PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:$PATH # standards(7): the POSIX.1-2001/SUSv3 order pfexec pkg install text/gnu-diffutils # OpenIndiana: a GNU tool from IPS ... PATH=/usr/gnu/bin:$PATH # ... lands in /usr/gnu/bin, put first ``` standards(7): where POSIX conflicts with the historical behaviour, the conforming tool is in `/usr/xpg4/bin` or `/usr/xpg6/bin`, and "An application that wants to use standard-conforming utilities must set the PATH". **The difference.** The `/usr/bin` versus `/usr/xpg4/bin` and `/usr/xpg6/bin` split is the same as illumos. A bare Solnix system has no `/usr/gnu`, and the finished system has no `pkg` (product.md): GNU grep and sed are `pkgs.solnix.gnugrep` and `pkgs.solnix.gnused`, used by store path (as the community builder module does for its gate's GNU grep) or from a profile. A package published to the Solnix cache must not start an executable with `#!/usr/xpg4/bin/sh`: publish gate check B9 fails a `#!` outside the store unless it is `/bin/sh`, `/usr/bin/sh` or `/usr/bin/env`. xz and libgpg-error hardcode it on `solaris*`; the aarch64 recipes were fixed. **Check.** Run `ls -l "$(command -v grep)"` (and the same for `sed`, `date`) under the PATH the script really gets: its own, the SMF method environment, or the build's. It holds when each tool is the variant whose flags the script uses. **Sources** - [.kiro/steering/product.md](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/.kiro/steering/product.md) (solnix 5a8e5ce), No IPS/`pkg` in the end product - [standards(7)](https://solnix.io/docs/man/standards.7) (illumos, CDDL), Utilities (xpg4/xpg6 directories, PATH order) - [grep(1)](https://solnix.io/docs/man/grep.1) (illumos), SYNOPSIS; HISTORY (former /usr/xpg4/bin versions now in /usr/bin) - [sed(1)](https://solnix.io/docs/man/sed.1) (illumos), SYNOPSIS; -i[extension] - [date(1)](https://solnix.io/docs/man/date.1) (illumos, CDDL), SYNOPSIS (/usr/bin/date, /usr/xpg4/bin/date); -r; %C - [ls(1)](https://solnix.io/docs/man/ls.1) (illumos, CDDL), SYNOPSIS (/usr/xpg4/bin/ls, /usr/xpg6/bin/ls); -v - [ksh93(1)](https://solnix.io/docs/man/ksh93.1) (illumos), whence -a; command -v - [modules/config/users.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/modules/config/users.nix) (solnix 5a8e5ce), shell default `/usr/bin/ksh93` - [lib/build-env.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/lib/build-env.nix) (solnix 5a8e5ce), each leaf is a symlink into a component's store path - [compare: grep(1)](https://solnix.io/docs/man/compare/grep.1), Perl regular expressions; -m missing; -b meaning; GNU grep via pkgs.solnix.gnugrep; portability tips - [compare: sed(1)](https://solnix.io/docs/man/compare/sed.1), long options and GNU-only flags; in-place extension argument; portability tips - [compare: date(1)](https://solnix.io/docs/man/compare/date.1), setting and parsing free-form dates; -r meaning; ISO 8601 output; %C meaning - [compare: ls(1)](https://solnix.io/docs/man/compare/ls.1), solnix note (xpg4/xpg6 ls); -v meaning - [handoff: from-builder-20261103T131454-a64h-aarch64-store-only-rows](https://codeberg.org/solnix/solnix-infra/src/commit/c2ecf4535e0fc32261bbfb2414bc7961a73fa6ca/docs/handoff/from-builder-20261103T131454-a64h-aarch64-store-only-rows/README.md), Gate findings on the way (B9 `#!/usr/xpg4/bin/sh`, same ksh93 as /bin/sh) - [handoff: from-builder-20261103T035251-gate2-client-checks](https://codeberg.org/solnix/solnix-infra/src/commit/c2ecf4535e0fc32261bbfb2414bc7961a73fa6ca/docs/handoff/from-builder-20261103T035251-gate2-client-checks.md), B9 row (allowed `#!` interpreters) - [modules/config/shell-environment.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/modules/config/shell-environment.nix) (solnix 5a8e5ce), basePathTail; environment.profiles (PATH search order) - [modules/config/system-path.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/modules/config/system-path.nix) (solnix 5a8e5ce), world seeded first so systemPackages win a clash; /usr/bin links to sw/bin - [modules/system/boot/init/smf.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/modules/system/boot/init/smf.nix) (solnix 5a8e5ce), environment (method_environment) - [configurations/extra-userland.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/configurations/extra-userland.nix) (solnix 5a8e5ce), opt-in coreutils gnugrep gnused in systemPackages - [configurations/installer.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/configurations/installer.nix) (solnix 5a8e5ce), "the full set would replace ls/cp/dd/df on /usr/bin, which links to sw/bin" - [modules/config/community/builder.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/modules/config/community/builder.nix) (solnix 5a8e5ce), GATE_GREP_DIR = `${s.gnugrep}/bin` - [lib/host-pkgs.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/lib/host-pkgs.nix) (solnix 5a8e5ce), "a bare system (dixi, EC2; no /usr/gnu)" - [modules/config/pgfarm.nix](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/modules/config/pgfarm.nix) (solnix 5a8e5ce), header (text/gnu-diffutils from IPS, /usr/gnu/bin first on an OpenIndiana-style host) - [OpenIndiana handbook: Common Tasks](https://docs.openindiana.org/handbook/common-tasks/#basic-unix-commands), Basic UNIX commands (GNU core utilities included)