8 + OPT_in_place = 1 << 0,
11 /* Each sed command turns into one of these structures. */
12 typedef struct sed_cmd_s {
13 /* Ordered by alignment requirements: currently 36 bytes on x86 */
14 @@ -938,8 +942,11 @@ static void process_files(void)
17 /* once matched, "n,xxx" range is dead, disabling it */
18 - if (sed_cmd->beg_line > 0)
19 + if (sed_cmd->beg_line > 0
20 + && !(option_mask32 & OPT_in_place) /* but not for -i */
22 sed_cmd->beg_line = -2;
24 sed_cmd->in_match = !(
25 /* has the ending line come, or is this a single address command? */
27 @@ -1270,9 +1277,6 @@ static void add_cmd_block(char *cmdstr)
28 int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29 int sed_main(int argc UNUSED_PARAM, char **argv)
32 - OPT_in_place = 1 << 0,
35 llist_t *opt_e, *opt_f;
36 int status = EXIT_SUCCESS;
37 @@ -1292,6 +1296,7 @@ int sed_main(int argc UNUSED_PARAM, char
39 opt_complementary = "e::f::" /* can occur multiple times */
41 + /* -i must be first, to match OPT_in_place definition */
42 opt = getopt32(argv, "irne:f:", &opt_e, &opt_f,
43 &G.be_quiet); /* counter for -n */
45 --- a/testsuite/sed.tests
46 +++ b/testsuite/sed.tests
47 @@ -270,11 +270,16 @@ testing "sed a cmd ended by double backs
51 -# fisrt three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges
52 +# first three lines are deleted; 4th line is matched and printed by "2,3" and by "4" ranges
53 testing "sed with N skipping lines past ranges on next cmds" \
54 "sed -n '1{N;N;d};1p;2,3p;3p;4p'" \
55 "4\n4\n" "" "1\n2\n3\n4\n"
57 +testing "sed -i with address modifies all files, not only first" \
58 + "cp input input2; sed -i -e '1s/foo/bar/' input input2 && cat input input2; rm input2" \
59 + "bar\nbar\n" "foo\n" ""
62 # testing "description" "arguments" "result" "infile" "stdin"