Bug 91497

Summary: The "-n" in "echo -n foo > /sys/bar" is not posix and not needed
Product: pm-utils Reporter: Alexandre Rostovtsev <tetromino>
Component: GeneralAssignee: Richard Hughes <richard>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: medium CC: fieldhouse, freedesktop-bugs
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: proposed patch
patch based on review of patch 117432 taken from running pm-functions

Description Alexandre Rostovtsev 2015-07-29 02:23:38 UTC
(reported downstream https://bugs.gentoo.org/show_bug.cgi?id=527848)

According to posix, the effect of the "-n" argument to echo is implementation-dependent. So a few shells, like the heavily patched variant of dash that Gentoo ships, do strange things with it - e.g. "echo -n foo" outputs "-n foo".

If such a shell is used as /bin/sh, the "echo -n mem /sys/power/state" calls in pm-utils will fail.

And that "-n" is not needed even when using bash: when writing to /sys/power/state, or almost anything else in /sys, the terminal newline doesn't make a difference.
Comment 1 Alexandre Rostovtsev 2015-07-29 02:28:53 UTC
Created attachment 117432 [details] [review]
proposed patch
Comment 2 /df 2016-02-22 20:19:05 UTC
Rather than changing all these, consider adding a shell function as follows:

echo()
{
	local fmt='%s\n'
	[ "$1" = "-n" ] && { fmt='%s'; shift; }
	printf "$fmt" "$*"
}

You can then redefine the existing log() function (line 90):

log()
{
	is_set "$LOGGING" || return 0;
	echo $*
}

This will (a) work on all platforms where log() now works (b) support use of "echo -n" in the code in case future contributors should introduce any.
Comment 3 /df 2016-02-28 01:27:24 UTC
Created attachment 122011 [details]
patch based on review of patch 117432 taken from running pm-functions
Comment 4 Adam Jackson 2018-06-29 19:57:07 UTC
pm-utils hasn't been touched in eight years, none of this is likely to get addressed. Closing bugs and disabling the bz product.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.