Copy Script Problems .....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Copy Script Problems .....
# 1  
Old 01-24-2002
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??
# 2  
Old 01-24-2002
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.
thehoghunter
# 3  
Old 01-24-2002
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
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 04:43 PM..
thehoghunter
# 5  
Old 01-24-2002
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
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
Try this it's easier

echo "Enter in the file name to be deleted"
read file
rm $file || echo "No file to delete"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy script output to a variable using same script?

I'm trying to copy script output and use it in this same script as a variable, and call the variable when script is compiled. The script is below. #!/bin/bash output=$(script) while read line; do if ]; then grep "$line" logfile.txt # Create text file echo "From: IT ... (4 Replies)
Discussion started by: SysAdminRialto
4 Replies

2. Shell Programming and Scripting

Shell Script Problems

Hi, I'm newbie in the shell script world and i want to solve some problems I am experiencing. My main goal is to create a ksh script to use 2 text files as input to execute a local shell script(create user commands in the criar.users.aix file) through a ssh connection in which the list of... (1 Reply)
Discussion started by: joaochambino
1 Replies

3. Homework & Coursework Questions

Problems executing script

Hi, I'm a complete novice to Linux and UNIX. I'm having trouble getting a script to execute properly. I did a similar script earlier in the semester with no problems. For whatever reason I can't get this one to work. Any help would be greatly appreciated as I'm completely lost and frustrated at... (5 Replies)
Discussion started by: Lindy70
5 Replies

4. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello, I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating! Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Discussion started by: facetoe
13 Replies

5. Shell Programming and Scripting

shell script to call perl script problems

Ok, don't ask me why, but all calls to perl must be called by a shell script. Its really not ideal, but its what I have to work with. Calling it isnt the issue, its passing in the arguments. I have about 1000 perl scripts to call by a shell script. Right now, I'm executing the shell script... (3 Replies)
Discussion started by: regexnub
3 Replies

6. UNIX for Dummies Questions & Answers

Problems with script and Cron

Hi Guys, total newbie here, Ive read through some of the threads about cron and scripts not working and have still drawn a blank as to why mine isnt working correctly. I have a script that runs the ausearch with a set of criteria i have setup, the only access i have to the system is via... (5 Replies)
Discussion started by: richie190784
5 Replies

7. Shell Programming and Scripting

two script problems

i have two problems with my phone book script the first i want to only allow a valid name if it has letters and spaces not a number in the name. so "joe smith" is ok "joe smith1" is not ok. the second problem is how can i cut a name out of a txt file i have this as my test txt file joe blogs... (3 Replies)
Discussion started by: zappedback
3 Replies

8. Shell Programming and Scripting

Script problems

Hi Can anybody please explain how the below script works and if there is any problems with it? The script is part of an archival process but it keeps crashing out. #!/sbin/sh - clear purgelist="/var/opt/moto/live/scripts/old_messages_purge_list" for i in `cat $purgelist` do ... (2 Replies)
Discussion started by: runnerpaul
2 Replies

9. UNIX for Dummies Questions & Answers

Stock script problems

I'm have some trouble, I'm doing some unix stuff for fun and I can't get something to work I have a getquote.sh script: wget "http://finance.yahoo.com/q?s=$1" -o /dev/null -O quote echo `echo $1; egrep "Last Trade:" quote | cut -d ">" -f 3 | cut -d "<" -f 1` to get the current trading price... (1 Reply)
Discussion started by: hinch
1 Replies

10. UNIX for Dummies Questions & Answers

script problems

Hi, Here is an example of a problem I have: File2: contain the following lines: a^ aaa^aa aa^~ b^ bbb^bb bb^~ c^ ccc^cc cc^~ d^ dddd^dd dd^~ File1: contain the following lines: b^ bbb^bb bb^~ c^ ccc^cc cc^~ I get File2 as input and I want to do as following: for each line in... (3 Replies)
Discussion started by: hellsd
3 Replies
Login or Register to Ask a Question