All pastes #466437 Raw Edit

Mover

public shellscript v1 · immutable
#466437 ·published 2007-04-30 23:53 UTC
rendered paste body
#!/bin/bash# A new mover.# Created by Kim Johansson# Released under GNU GPL v2.0# Set this files name.NAME="renamer"# Check if we have more than two arguments.# -z is to check if a string is empty. With ! before it's negated, if the string is not empty.if [ ! -z $3 ]	then	echo -e "Usage: $NAME file1 file2"# Proper exit status if something went wrong.	exit 1fiDONE="no"while [ "$DONE" != "yes" ]do	if [ -z $1 ]		then		echo -e -n "File to rename: "		read FILE_TO_RENAME		if [ -e $FILE_TO_RENAME ]			then DONE="yes"		else			echo -e "File does not exist."		fi	else		FILE_TO_RENAME=$1		if [ ! -e $FILE_TO_RENAME ]			then			echo -e "File does not exists."			exit 1		else			DONE="yes"		fi	fidoneDONE="no"while [ "$DONE" != "yes" ]do	if [ -z $2 ]		then		echo -e -n "New name: "		read NEW_NAME		if [ ! -e $NEW_NAME ]			then DONE="yes"		else			echo -e "File exists."		fi	else		NEW_NAME=$2		if [ ! -e $NEW_NAME ]			then DONE="yes"		else			echo -e "File exists."			exit 1		fi	fidone# Finally, use the mv command to rename the file.mv $FILE_TO_RENAME $NEW_NAME# Proper exit status.exit 0