Moving file(s) from dir to dir

Hi, I am fairly new to writing scripts.

I am trying to write a script that moves either One or All of the files from one directory to another.

I know how to make the actual command to do it, but i don't quite know how to add operators to it, ie -i or -a.

I want -i to move one file from the directory, asking the user to confirm if he/she wants to move this file or not.

And -a to move all the files to the other directory.

I would really appreciate any help that anyone can give me.

Thanks

Joeh.

Maybe getopts is interessting for you:
Linux.com :: SysAdmin to SysAdmin: More power with bash getopts

Else you can try parsing $1 and $2 (shell parameter variables) with if/then/fi or case etc.

I honestly cannot do this.
The information may be very helpful, but I can't actually bring myself to read it.
My brain just isn't working right now, and I can't be bothered reading it.

hey I am providing you the below skeleton of your requirement, going forward please modify it as per your requirement

no_param=$#

if [ ${no_param} -ne 1 ]
then
	echo "Please execute the script with i/p as i(single) or a(all),"
	echo "`basenmae $0` i or a "
	exit 1
fi

case $1
in
"a") 	for i in $(ls -1 <input dir>| grep -v "^\.")
	do
	mv <input dir>/$i  <destination dir>	
	done
	;;
"i")    echo "please type the file you want to move"
	read input_file
	if [ ! -f "<input dir>/${input_file}" ]
	then
		echo "${input_file} doesn't exist."
		exit 1
	else
		mv <input dir>/${input_file} <destination dir>	

	fi
	;;
*)	echo "please enter your input correctly."
	exit 1
	;;
esac

NOTE: I have not tested it in any environment.

hey, thanks that was a big help :smiley: