LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-23-2006, 02:24 AM   #1
kb100
Member
 
Registered: Aug 2006
Posts: 43

Rep: Reputation: 15
simple scripting help please


Hi there was wondering if anyone can help. My script doesnt seem to work. I am trying to ask the user for a first argument (original file) and the second argument (other file). If user does not provide two arguments the script will exit. If the filename already exists the script will prompt user whether to overwrite the file. Heres what i have done:

#!/bin/sh
clear
echo "Enter filename"
read filename

if -grep $filename rename.sh
then
echo "This filename does not exist"


echo "Enter second filename you wish to display"
read filename2

if -grep $filename2 info.txt
then
echo "filename does not exist"
echo "Do you wish to create this file y/n?"
read verdict
if [$verdict -eq "y"]
then
echo filename >> filename2
elif [$verdict -eq "n"]
then
echo "You have chosen not to create. It will now exit"


clear
fi

exit

thanks
 
Old 08-23-2006, 02:41 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by kb100
if -grep $filename rename.sh
Please use code tags around your code samples.

The "if -grep" construction doesn't exist is bourne shell.

Thy instead:
Code:
if grep $filename rename.sh
then
...
 
Old 08-23-2006, 02:50 AM   #3
kb100
Member
 
Registered: Aug 2006
Posts: 43

Original Poster
Rep: Reputation: 15
thanks for reply.
am i doing the right things though? i ask user for filename


#!/bin/sh
clear
echo "Enter filename"
read filename

then i search for that filename in my file. Is it supposed to search a directory?

if grep $filename rename.sh
then
echo "This filename does not exist"

i then ask user to enter second filename.

echo "Enter second filename you wish to display"
read filename2

if grep $filename2 info.txt
then
echo "filename does not exist"
echo "Do you wish to create this file y/n?"
read verdict
if [$verdict -eq "y"]
then
echo filename >> filename2
elif [$verdict -eq "n"]
then
echo "You have chosen not to create. It will now exit"


am i doing it right?

thanks
 
Old 08-23-2006, 02:59 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by kb100
am i doing it right?
No, you still aren't using code tags.

If you do not understand what I mean, click on the "go advanced" button, select the part to wrap with code tags, then click on the "#" icon on the top icon bar.
 
Old 08-23-2006, 03:03 AM   #5
kb100
Member
 
Registered: Aug 2006
Posts: 43

Original Poster
Rep: Reputation: 15
sorry i dont understand. What "go advanced button"?
what tags?
 
Old 08-23-2006, 03:07 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by kb100
sorry i dont understand. What "go advanced button"?
The one at the bottom of the editing window you are using to post when you are in "Quick Reply" mode.
Quote:
what tags?
the code tag.
 
Old 08-23-2006, 03:13 AM   #7
kb100
Member
 
Registered: Aug 2006
Posts: 43

Original Poster
Rep: Reputation: 15
thanks. sorry didnt know what tags you were talking about. Do now.
am i doing the right things though? i ask user for filename

Code:
#!/bin/sh
clear
echo "Enter filename"
read filename
then i search for that filename in my file. Is it supposed to search a directory?

Code:
if grep $filename rename.sh 
then
echo "This filename does not exist"
i then ask user to enter second filename.

Code:
echo "Enter second filename you wish to display"
read filename2

if grep $filename2 info.txt
then
echo "filename does not exist"
echo "Do you wish to create this file y/n?"
read verdict
if [$verdict -eq "y"]
then
echo filename >> filename2
elif [$verdict -eq "n"]
then
echo "You have chosen not to create. It will now exit"
am i doing it right?

thanks
 
Old 08-23-2006, 06:31 AM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by kb100
thanks. sorry didnt know what tags you were talking about. Do now.
am i doing the right things though? i ask user for filename

Code:
#!/bin/sh
clear
echo "Enter filename"
read filename
then i search for that filename in my file. Is it supposed to search a directory?

Code:
if grep $filename rename.sh 
then
echo "This filename does not exist"
Either the test or the message is wrong, grep is looking for the string the variable "filename" represent. It looks for this string in the file which name is "rename.sh".

It doesn't make a lot of sense.
Quote:

i then ask user to enter second filename.

Code:
echo "Enter second filename you wish to display"
read filename2

if grep $filename2 info.txt
then
echo "filename does not exist"
echo "Do you wish to create this file y/n?"
read verdict
if [$verdict -eq "y"]
then
echo filename >> filename2
elif [$verdict -eq "n"]
then
echo "You have chosen not to create. It will now exit"
am i doing it right?
This code is incomplete.

Last edited by jlliagre; 08-23-2006 at 06:32 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
simple scripting help please kb100 Programming 12 08-18-2006 08:34 AM
simple scripting help please kb100 Programming 3 08-18-2006 08:08 AM
Simple Shell Scripting Question hellomynameisphil Programming 2 08-27-2005 03:41 AM
simple scripting question wedgeworth Programming 6 02-04-2004 10:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration