~emersion/mrsh-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] make read return 1 when an EOF is encountered

Details
Message ID
<20200203214354.21538-1-lattis@mochiro.moe>
DKIM signature
missing
Download raw message
Patch: +24 -1
For instance:
echo "hi" | read arg
should have an exit code of >0 per the POSIX spec

- a test was also added
---
 builtin/read.c   |  7 ++++++-
 test/meson.build |  1 +
 test/read.sh     | 17 +++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 test/read.sh

diff --git a/builtin/read.c b/builtin/read.c
index d014969..a0ce82e 100644
--- a/builtin/read.c
@@ -97,5 +97,10 @@ int builtin_read(struct mrsh_state *state, int argc, char *argv[]) {
		free(fields.data[i]);
	}
	mrsh_array_finish(&fields);
	return 0;

	if (c == EOF) {
		return 1;
	} else {
		return 0;
	}
}
diff --git a/test/meson.build b/test/meson.build
index fd8aefb..b58720a 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -12,6 +12,7 @@ test_files = [
	'function.sh',
	'loop.sh',
	'pipeline.sh',
	'read.sh',
	'readonly.sh',
	'redir.sh',
	'return.sh',
diff --git a/test/read.sh b/test/read.sh
new file mode 100644
index 0000000..e77e072
--- /dev/null
+++ b/test/read.sh
@@ -0,0 +1,17 @@
#!/bin/sh -eu


printf | read a
echo $?

i=0

printf "a\nb\nc\n" | while read line; do
  printf "%s\n" "${line:-blank}"

  i=$((i+1))

  [ $i -gt 10 ] && break
done

[ $i = 3 ] && echo "correct!"
-- 
2.24.1
Details
Message ID
<jMB_0xbBBOS0Do2MLdk0QUffnCBVTliowBwF_K24UwqJswwqeNh4-Fa6I-IdRYqDgCXUVYbc6pgZ_qxgJTHjOAPh2ONFk7kSUxDlycmgix0=@emersion.fr>
In-Reply-To
<20200203214354.21538-1-lattis@mochiro.moe> (view parent)
DKIM signature
missing
Download raw message
LGTM. Slightly edited the commit message and pushed.

Thanks!
Review patch Export thread (mbox)