Commit Diff


commit - 81e077a6cea50b04ac9be4f63abd004846653251
commit + 186c23b673fcf9cdcb51b82bd9b3aa47740f704d
blob - 62bac29f8ab8fb7946953e3905626640011f47c8
blob + 250039808d02f0f288ebaf1fcc148bbf83f4e255
--- regress/cmdline/common.sh
+++ regress/cmdline/common.sh
@@ -45,14 +45,26 @@ ln()
 sed()
 {
 	SEDCMD="sed"
+
+	# On non-linux systems, the sed command can happily accept "-i ''" as
+	# a valid command to not save backup files for in-place edits.
+	# However, on linux, "-i ''" would be treated as "-i" with a blank
+	# argument, and hence, no file to edit in-place, which is an error.
+	#
+	# Therefore, scan the argument list and remove "-i ''", replacing it
+	# with just "-i".
 	[ "$PLATFORM" = "linux" ] && {
 		set -- "$@"
-		[ $# -ge 4 ] && {
-			shift 2
-			
-			command "$SEDCMD" -i "$@"
-			return
-		}
+		i=1
+		while [ "$i" -le "$#" ]; do
+			m=$((i + 1))
+			[ "${!i}" = "-i" ] && [ -z "${!m}" ] && {
+				shift 2
+				command "$SEDCMD" -i "$@"
+				return
+			}
+			i=$((i + 1))
+		done
 	}
 	command "$SEDCMD" "$@"
 }