All pastes #933274 Raw Edit

Something

public shellscript v1 · immutable
·published 2008-03-08 06:17 UTC
rendered paste body
## This script adds or removes the specified extension to all files in the# specified directory.if [ $# -lt 2 ]; then  echo "Options: -a -r  -d" >&2  echo "Please provide a file extension to add or remove"  echo "You may also provide a directory. If none is provided, the current"  echo "directory will be used."  exit 1fidch {  if [ -d "$1" ]; then    cd "$1"    cur=0  elseif [ "$1" = -d ]; then    incl=y  fi}cur=1while [ -n "$1" ]; do  dch "$1"  if [ "$1" = -a ]; then    dch "$3"    dch "$4"    for c in '*'; do      if ! [ "$c" = change -a "$cur" = 1 ]; then        if [ -d "$c" -a "$incl" != y ]; then          continue        fi        mv "$c" "$c.$2"        ((f=f+1))      fi    done  elseif [ "$1" = -r ]; then    dch "$3"    dch "$4"    for c in *; do      if ! [ "$c" = change -a "$cur" = 1 ]; then        if [ -d "$c" -a "$incl" != y ]; then          continue        fi        mv "$c" "${c%.$2}" 2> /dev/null        ((f=f+1))      fi    done  fi  shiftdoneecho "$f files changed."exit 0