![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| How to run an SQL script inside a shell | stevefox | Shell Programming and Scripting | 1 | 06-15-2006 10:11 PM |
| How to run unix commands in a new shell inside a shell script? | hkapil | Shell Programming and Scripting | 2 | 01-04-2006 06:56 AM |
| If a is windows gui ( client), b is a unix gui ( Server for a) and c is a shell scrip | hchivukula | UNIX for Dummies Questions & Answers | 1 | 06-12-2005 08:34 AM |
| Execute an Oracle stored procedure from a shell scrip | mh53j_fe | Shell Programming and Scripting | 1 | 06-03-2005 03:17 PM |
| Using tar inside a shell script | kas7225 | Shell Programming and Scripting | 2 | 05-19-2005 11:06 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using cp command inside shell scrip
Hi,
First i would like to say that im a unix begginer. I have a file named /tmp/sample.lst that contain about 20 rows like the following two : '/tmp/aa.txt' '/temp/aa.txt' '/tmp/xx.txt' '/temp/xx.txt' Inside a ksh script i would like to do the following task: add the cp command at the begging of each line, and after that check if the copy command successed. for example: cp `cat /tmp/sample.lst` if [ st$ -eq != 0 ] then echo "fail" else echo "success" fi Could one demonstraite how to run through the lines and check if each copy succeded ? Thank You Very Much !!!! ![]() |
|
||||
|
Might be better to test the return code rather than existence of file - this would pick up errors like unable to overwrite existing file because of permissions, lack of space etc, also I'd like a specific error message - but them I'm just picky
Quote:
Code:
if [ $? -eq 0 ] ; then
echo "$destfile copied successfully from $sourcefile"
else
echo "ERROR: failed to copy $destfile from $sourcefile"
fi
done < /tmp/sample.lst
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|