archieoboyle
Posts: 10
Joined: Sun Apr 06, 2014 2:04 pm

Shell script

Mon Apr 21, 2014 4:20 pm

Hi,
Anyone have any idea how you could write a shell script that takes a string input from a user, asks for a file name and reports whether that string is present in the file?
Any help on this would be great!

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Shell script

Mon Apr 21, 2014 5:07 pm

It might be cheating, but the command already exists - it is called grep.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

archieoboyle
Posts: 10
Joined: Sun Apr 06, 2014 2:04 pm

Re: Shell script

Mon Apr 21, 2014 8:28 pm

Hahaha! thanks for the help, but need a shell script really.

thanks anyway!

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Shell script

Mon Apr 21, 2014 8:52 pm

archieoboyle wrote:Hahaha! thanks for the help, but need a shell script really.

thanks anyway!
But why can't you use grep in a shell script?

A shell script is just a series of ordinary commands with a few additions after all...

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: Shell script

Mon Apr 21, 2014 9:04 pm

Perhaps it is a homework question...
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

JCoomber
Posts: 3
Joined: Tue Apr 22, 2014 9:40 am

Re: Shell script

Tue Apr 22, 2014 9:44 am

I see we've both hit rock bottom Archie, searching the exact question on google the day before its due in. :D

Return to “Advanced users”