The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names nikosey Shell Programming and Scripting 6 07-30-2008 09:46 PM
file moving based on file content melvyn.cochrane Shell Programming and Scripting 12 02-15-2008 06:10 AM
Problem while moving a file smvel Shell Programming and Scripting 5 06-10-2005 04:06 AM
moving a file? Holistic UNIX for Dummies Questions & Answers 1 02-20-2003 07:47 PM
moving or removing a file rooh UNIX for Dummies Questions & Answers 3 01-02-2002 02:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-22-2009
SirJoeh SirJoeh is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 3
Question 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.
  #2 (permalink)  
Old 01-22-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,262
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.
  #3 (permalink)  
Old 01-22-2009
SirJoeh SirJoeh is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 3
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.
  #4 (permalink)  
Old 01-22-2009
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
hey I am providing you the below skeleton of your requirement, going forward please modify it as per your requirement
Code:
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.
  #5 (permalink)  
Old 01-23-2009
SirJoeh SirJoeh is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 3
hey, thanks that was a big help
Closed Thread

Bookmarks

Tags
dir, directory, move, operators, scripts

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0