Solved

Linux Shell Script for copy file

Posted on 2014-09-16
3
442 Views
Last Modified: 2014-09-16
I am new to Linux Shell Script. With help from my previous posting, i was able to get a sample code from an expert.

My requirement is to call the .sh file from .Net Application. My Application will pass SourceFilePath and DestinationFilePath as Paramaters.

I expect Shell Script to get the parameters as Input and Copy/Paste the file.

How to customize my sample code with Parameters in it ?


#vim script.sh
echo "\home\testuser\file.csv"
read a
echo "\home\admin\user2\data\file.csv"
read b
echo "Data will be moving from $a to $b"
mv $a  $b
echo "Moving done"

:wq

#chmod u+x script.sh
#./script.sh

Open in new window

0
Comment
Question by:chokka
3 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 250 total points
ID: 40325746
Easiest would be

    mv $1 $2

then you call it as

    ./script.sh /home/testuser/file.csv /home/admin/user2/destination/file.csv

(UNIX/Linux use forward slashes between directories, Windows uses backslash)
0
 
LVL 14

Assisted Solution

by:ThomasMcA2
ThomasMcA2 earned 250 total points
ID: 40325777
Also, if your input paths might include spaces, wrap the parms with double quotes, like this:

mv "$1" "$2"
0
 
LVL 23

Expert Comment

by:savone
ID: 40325829
mv would be a move, which would be like a cut and paste as opposed to copy and paste.  

Try this...


echo "Copying $1 to $2"
cp "$1" "$2"
echo "Copy completed"

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This video demonstrates basic masking and how to edit the mask to reveal the desired image.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now