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
cp can not access HIEUNK Shell Programming and Scripting 5 04-26-2008 10:46 AM
ssh access mm00123 SUN Solaris 8 08-30-2007 04:12 AM
FTP Access sehgalniraj UNIX for Dummies Questions & Answers 3 08-26-2005 05:39 PM
How to access CD sam71 UNIX for Dummies Questions & Answers 2 07-20-2005 02:53 PM
Need help to access/mount so to access folder/files on a Remote System using Linux OS S.Vishwanath UNIX for Dummies Questions & Answers 2 07-30-2001 08:17 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-07-2003
nguda nguda is offline
Registered User
  
 

Join Date: May 2002
Posts: 25
cp: cannot access

Hi All,
I have the following script, where I am copying a list of files from one location to another location. The permissions, owners are fine. Why i am getting cp: cannot access error when i run this script. But the cp works at command prompt...

files="home/file.lst"
for file in `cat $files`
do
cp $file $HOME/copy
done
Please help. Thanks.
  #2 (permalink)  
Old 11-07-2003
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
files="home/file.lst"
for file in `cat $files`
do
cp $file $HOME/copy
done
Please help. Thanks.


check your files variable. The path should probably look like this files="/home/file.lst"
  #3 (permalink)  
Old 11-07-2003
nguda nguda is offline
Registered User
  
 

Join Date: May 2002
Posts: 25
Nope..., it is still not working...
  #4 (permalink)  
Old 11-07-2003
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Quote:
Originally posted by nguda
files="home/file.lst"
for file in `cat $files`
do
cp $file $HOME/copy
done
I should have noticed this before. Your cp command is over writing each of the previous copies! So you will end up with one file in your $HOME dir named copy. Why are you doing this? I assume its a typo. You need to change the destination file name. Also, check permissions again.

This is not the reccomended naming convention, just wanted to illustrate my point!

COUNT=0
FILES=$(cat /home/file.lst)
for file in $FILES
do
cp $file $HOME/copy_$COUNT
let COUNT +=1
done
  #5 (permalink)  
Old 11-07-2003
nguda nguda is offline
Registered User
  
 

Join Date: May 2002
Posts: 25
This is not "for" problem...
I don't think when we use for loop we have to do the explicit couting again.... is is not a while loop...
Sponsored Links
Closed Thread

Bookmarks

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 07:04 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