The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to copy a usb key jo calamine Shell Programming and Scripting 1 09-23-2006 06:29 AM
Help:Copy file from one to other using script sunnysunny Shell Programming and Scripting 2 08-07-2006 07:45 AM
copy script scbrown2 Shell Programming and Scripting 2 05-01-2006 01:02 PM
copy files without password in script jwala Shell Programming and Scripting 0 02-12-2006 10:10 AM
Help with Copy Move Script alfpathros Shell Programming and Scripting 4 05-11-2004 05:52 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-24-2002
Registered User
 

Join Date: Dec 2001
Location: UK, England
Posts: 45
How do I....

I got this script:

print -n "Enter file name: "
read name
....
.....
.....
etc

but at the prmpt, when I press enter (without typin a word), comes up with sum error message, is there away of getting it not to print that message??
Forum Sponsor
  #2  
Old 01-24-2002
thehoghunter
Guest
 

Posts: n/a
More information is required (like the error message and more of the code) as the code you did put here does not come up with an error message.
  #3  
Old 01-24-2002
Registered User
 

Join Date: Dec 2001
Location: UK, England
Posts: 45
print -n "Enter file name to be deleted: "
read name
if [ -f $name ]
then
rm $name
echo "file: $name has been deleted"
else
echo "this is not a file"
fi

This is the error message: usage: rm [-fiRr] file ...

When the promt "Enter file name to be deleted" comes up press enter (return).
  #4  
Old 01-24-2002
thehoghunter
Guest
 

Posts: n/a
Strange... I typed your code in and it worked fine - no error.
I copied it and then I got the error but I don't know why.
(I am also assuming /bin/ksh on this)
I added quotes in the if statement - it seems to work
./testone
Enter file name: junk2
file junk2 deleted
medusa% ./testone
Enter file name:
No such file
medusa% more testone
Code:
#!/bin/ksh
print -n "Enter file name: "
read name
if [ -f "$name" ]
then
        rm $name
        echo "file $name deleted"
else
        echo "No such file"
fi
exit
added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 01:43 PM.
  #5  
Old 01-24-2002
Registered User
 

Join Date: Dec 2001
Location: UK, England
Posts: 45
Copy error message....

When the promt "Enter file name to be copied" comes up press enter (return), I get an error message, is there a new of getting rid of it or round it??


Copyfile () {
print -n "Enter file name to be copied: "
read sourcefile
if test ! -f $sourcefile
then
echo "File doesnt exist, press enter"
read answer
else
print -n "Enter name of new file that will hold contents of "$sourcefile
read targetfile
if test -f $targetfile
then
echo "The name: $targetfile is already in use"
else
cp $sourcefile $targetfile
echo "$sourcefile copied"

print -n "Do u want to repeat, and copy another"
read answer
case $answer in
[yY]) Copyfile ;;
[nN]) break ;;
*) echo " Do you want to repeat (y/n)?? "
  #6  
Old 01-25-2002
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Code:
read sourcefile 
if test ! -f $sourcefile 
then 
echo "File doesnt exist, press enter"
Try putting quotes around the $sourcefile...
Think of it this way:
if you just press return, $sourcefile is empty.
so the statement evaluates to:
"if test ! -f "
Same with the rm example that was first posted.
Trying checking to make sure the $sourcefile is not empty...
  #7  
Old 01-25-2002
Registered User
 

Join Date: Sep 2001
Location: Switzerland
Posts: 13
Try this it's easier

echo "Enter in the file name to be deleted"
read file
rm $file || echo "No file to delete"
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0