Refer to the exhibit. An administrator needs to edit /etc/example.conf to change setting1 to 'production' and add a new line 'setting2=value' after the include line. The file must be edited in place without creating a backup. Which command sequence achieves this?
Trap 1: sed -i 's/setting1=default/setting1=production/' /etc/example.conf;…
The second sed uses 'i' (insert before) rather than 'a' (append after), so setting2=value lands above the include line, not after it. Insert is tempting because both edit relative to a matched line, but only append satisfies the stem's placement requirement.
Trap 2: sed -i.bak 's/setting1=default/setting1=production/'…
The -i.bak suffix creates a backup file, directly violating the requirement to edit in place without a backup. Backup suffixes are tempting because they are the standard safety measure when editing configuration with sed, and would be correct if the stem permitted backups.
Trap 3: sed -i.bak 's/setting1=default/setting1=production/'…
Identical to the previous option: -i.bak writes a .bak copy, breaching the no-backup requirement. Retaining a backup is tempting as prudent practice for configuration edits, and would be the right approach whenever rollback safety matters more than the stated constraint.
- A
sed -i 's/setting1=default/setting1=production/' /etc/example.conf; sed -i '/^include /a\nsetting2=value' /etc/example.conf
GNU sed's `-i` flag edits the file in place, satisfying the no-backup constraint, while the `a\` command appends `setting2=value` after the matching include line. Two sequential invocations work because each substitution targets a distinct pattern, and `-i` without a suffix writes directly to the original file.
- B
sed -i 's/setting1=default/setting1=production/' /etc/example.conf; sed -i '/^include /i\nsetting2=value' /etc/example.conf
Why it fails: The second sed uses 'i' (insert before) rather than 'a' (append after), so setting2=value lands above the include line, not after it. Insert is tempting because both edit relative to a matched line, but only append satisfies the stem's placement requirement.
- C
sed -i.bak 's/setting1=default/setting1=production/' /etc/example.conf; sed -i.bak '/^include /a\nsetting2=value' /etc/example.conf
Why it fails: The -i.bak suffix creates a backup file, directly violating the requirement to edit in place without a backup. Backup suffixes are tempting because they are the standard safety measure when editing configuration with sed, and would be correct if the stem permitted backups.
- D
sed -i.bak 's/setting1=default/setting1=production/' /etc/example.conf; sed -i.bak '/^include /a\nsetting2=value' /etc/example.conf
Why it fails: Identical to the previous option: -i.bak writes a .bak copy, breaching the no-backup requirement. Retaining a backup is tempting as prudent practice for configuration edits, and would be the right approach whenever rollback safety matters more than the stated constraint.