![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
Last edited by oombera; 02-19-2004 at 01:43 PM. |
|
#5
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
read sourcefile if test ! -f $sourcefile then echo "File doesnt exist, press enter" 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
|
|||
|
|||
|
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 |