All pastes #1851950 Raw Edit

sh

public shellscript v1 · immutable
#1851950 ·published 2010-03-24 23:16 UTC
rendered paste body
#!/bin/bash -eif [ $# -ne 2 ]; then	echo >/dev/stderr "ERROR: Incorrect number of arguments."	cat <<EODUsage:	./`basename "$0"` LIST NAMEArguments:	LIST	File containing names of files to rename.	NAME	Beginning of pattern to rename files to.EOD	exit -1fiif [ "$1" == "-" ]; then	FILELIST="/dev/stdin"else	FILELIST="$1"	if [ ! -f "$FILELIST" ]; then		echo >/dev/stderr "ERROR: Could not read file list '$FILELIST'."		exit -1	fifiNAMEPATN="$2"i=1while read FIN; do	if [ ! -f "$FIN" ]; then		echo >/dev/stderr "WARNING: Could not find source file '$FIN'. Skipping..."		continue	fi	FOUT=`printf "$NAMEPATN.part%03d.rar" $i`	if [ -f "$FOUT" ]; then		echo >/dev/stderr "WARNING: Target file '$FOUT' alread exists. Skipping..."		continue	fi	mv -v "$FIN" "$FOUT"	i=$[$i+1]done <"$FILELIST"