logo

utils-std

Collection of commonly available Unix tools
commit: a952e5be0a75ee5d8cce4008ccff44b2a9050c8e
parent b6d5e3388916b2f608a91a94965cecab7d5886b2
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 12 Apr 2024 02:04:10 +0200

cmd/yes: new

Diffstat:

M.gitignore1+
MMakefile7+++++--
Acmd/yes13+++++++++++++
Acmd/yes.130++++++++++++++++++++++++++++++
Atest-cmd/yes.t26++++++++++++++++++++++++++
5 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -4,6 +4,7 @@ /config.mk /target_filter /cmd/* +!/cmd/yes !/cmd/*.c !/cmd/*.ha !/cmd/*.1 diff --git a/Makefile b/Makefile @@ -3,6 +3,9 @@ include config.mk +# Commands implemented as scripts +SCRIPTS=cmd/yes + all: $(EXE) $(MAN1SO) .c: @@ -29,7 +32,7 @@ check-libs: $(TEST_LIBS) .PHONY: lint lint: $(MAN1SO) - $(SHELLCHECK) ./configure ./test_functions.sh + $(SHELLCHECK) ./configure ./test_functions.sh $(SCRIPTS) ${FLAWFINDER} --minlevel=3 --error-level=4 . $(MANDOC) -Tlint -Wunsupp,error,warning $(MAN1) $(REUSE) lint --quiet @@ -41,7 +44,7 @@ clean: install: all mkdir -p ${DESTDIR}${BINDIR}/ - cp -p ${EXE} ${DESTDIR}${BINDIR}/ + cp -p ${EXE} ${SCRIPTS} ${DESTDIR}${BINDIR}/ mkdir -p ${DESTDIR}${MANDIR}/man1 cp -p ${MAN1} ${DESTDIR}${MANDIR}/man1 diff --git a/cmd/yes b/cmd/yes @@ -0,0 +1,13 @@ +#!/bin/sh +# utils-std: Collection of commonly available Unix tools +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + +die() { + echo "yes: $@" >&2 + exit 1 +} + +while true; do + echo "${@:-y}" || die "Write error" +done diff --git a/cmd/yes.1 b/cmd/yes.1 @@ -0,0 +1,30 @@ +.\" utils-std: Collection of commonly available Unix tools +.\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +.\" SPDX-License-Identifier: MPL-2.0 +.Dd 2024-04-12 +.Dt YES 1 +.Os +.Sh NAME +.Nm yes +.Nd output a string repeatedly +.Sh SYNOPSIS +.Nm +.Op Ar string ... +.Sh DESCRIPTION +The +.Nm +utility repeatedly prints +.Ar string +or by default 'y'. +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr echo 1 +.Sh STANDARDS +None known. +.Sh HISTORY +The +.Nm +command appeared in Version 7 AT&T UNIX. +.Sh AUTHORS +.An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me diff --git a/test-cmd/yes.t b/test-cmd/yes.t @@ -0,0 +1,26 @@ +#!/usr/bin/env cram +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: MPL-2.0 + + $ export PATH="$TESTDIR/../cmd:$PATH" + + $ test "$(command -v yes)" = "$TESTDIR/../cmd/yes" + + $ yes | head -3 + y + y + y + $ yes foo | head -4 + foo + foo + foo + foo + $ yes $'foo\nbar\n' | head -5 + foo + bar + + foo + bar + $ yes >/dev/full + yes: Write error + [1]