#!/bin/csh -f # mdmv # ------------------------------------------------------------------------------ # Shell script to move a file, creating nested target directories as needed. # ------------------------------------------------------------------------------ # Usage: See Usage section below or run with no arguments to see usage. # Assumptions: # Effects: # - Moves a file and creates containing target dirs. # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ------------------------------------------------------------------------------ set option = if ("$1" == "-i") then set option = "$1" shift endif if ($#argv < 2) then echo "Usage: $0:t [-i] source_filename target_filename_or_existing_dir" exit 1 endif # Create nested target directories as needed. set rc = 0 set target_path = "$2" if (-d "$target_path") then # Target param was an existing path. No need to create the path. # The move command will move the file to that path. else # Target param is not an existing path. May be a file or non-existent. # Try to create the parent path, if any, to hold the target file. set target_path = "$2:h" if ("$target_path" != "") then mkdir -p -v "$target_path" set rc = $status endif endif if ($rc == 0) then # Use :q instead of "" in case option is empty. Generates nothing instead of # an empty quoted string which would be counted as first arg. mv -v $option:q "$1" "$2" set rc = $status endif exit $rc