← Back to problems
UNSW COMP2041 · hard

21T2 Q7 — Print rename-with-extension commands

For each filename argument print exactly one line (do not rename anything):

  • has a . → # <f> already has an extension
  • no #! first line → # <f> does not have a #! line
  • #! line has none of python/perl/sh → # <f> no extension for #! line
  • the target <f><ext> already exists → # <f><ext> already exists
  • otherwise → mv <f> <f><ext> (.py/.pl/.sh from python/perl/sh in the #! line).

POSIX shell only (#!/bin/dash); standard UNIX filters; no awk, Perl, C or Python. From COMP2041/9044 21T2 Final.