LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-05-2011, 03:30 AM   #1
afiqrahim
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Rep: Reputation: Disabled
Script shell programming


Does anyone have any ideas, i mean codes on how to write a bash script for locate file.
e.g:
This utility shows you all files and directories that have a specific
substring in the name.
Press '?' for help, 'q' for quit or enter your search terms:
Kuala bin
I have searched for two terms for you,
Kuala, which has three hits:
/usr/share/zoneinfo/Asia/Kuala_Lumpur
/usr/share/zoneinfo/posix/Asia/Kuala_Lumpur
/usr/share/zoneinfo/right/Asia/Kuala_Lumpur
bin, which has 2312 hits. Are you sure you want to see all of those? [Y/n]
n
Press '?' for help, 'q' for quit or enter your search terms:
Sorry, you didn't enter any search term.
Press '?' for help, 'q' for quit or enter your search terms:
q
Thanks for being here, come again.
$
 
Old 08-05-2011, 03:52 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
So what exactly is your question? The script / command seems to work just fine based on what you have shown.
 
1 members found this post helpful.
Old 08-05-2011, 09:17 AM   #3
afiqrahim
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
I want to know the codes for an output like above.
The question that was given by my teacher is to locate file(s) by by keyword.
Above is the example of the output.
I would appreciate it if you could help me.
Thanks in advance.
 
0 members found this post helpful.
Old 08-05-2011, 09:22 AM   #4
afiqrahim
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
grail,
the main important thing is the shell script codes for locate file(s).
It doesn't necessarily have to be exactly as stated above.
Any creative ideas would be great.
Thanks in advance.
:-)
 
0 members found this post helpful.
Old 08-05-2011, 09:35 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by afiqrahim View Post
I want to know the codes for an output like above.
The question that was given by my teacher is to locate file(s) by by keyword.
Above is the example of the output.
I would appreciate it if you could help me.
Thanks in advance.
So your teacher gave you an assignment with suggested output...and you'd like us to write your script for you? Sorry, no. We will be glad to ASSIST you..post what you've written so far, what you've tried, and where you're stuck, and we'll help you out. Otherwise, there are THOUSANDS of bash scripting guides you can easily find with Google, like this one:
http://tldp.org/LDP/abs/html/

Read the man pages on the find command, and look up the case statements in bash scripting.
 
1 members found this post helpful.
Old 08-05-2011, 05:41 PM   #6
afiqrahim
LQ Newbie
 
Registered: Aug 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
So your teacher gave you an assignment with suggested output...and you'd like us to write your script for you? Sorry, no. We will be glad to ASSIST you..post what you've written so far, what you've tried, and where you're stuck, and we'll help you out. Otherwise, there are THOUSANDS of bash scripting guides you can easily find with Google, like this one:
http://tldp.org/LDP/abs/html/

Read the man pages on the find command, and look up the case statements in bash scripting.
You're so provocative. I never ask you to practically DO my assignment. Any little tips would do. I already have the output. I just wanna brush it up a bit.
It was my lecturer himself who asked me to ask questions from this page.

Last edited by Tinkster; 08-05-2011 at 08:25 PM. Reason: Language clean-up....
 
0 members found this post helpful.
Old 08-05-2011, 08:37 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
afiqrahim I'd like to ask you to not get personal. Other people
have the right to comment on your actions/questions, it's not your
right to get all the answers you desire, it's a privilege you're
granted to be asking questions. How people respond will not always
be what you expect or want to hear, just get over it.


TBOne, please try to be a bit kinder on people, specially new ones.
Yes, I've read ESR's "How to ask questions" and his idea of netiquette.

The problem is that we're not all the same, not all with the
same background, and obviously not all the same cultural backgrounds -
be that regarding the country/culture of origin, or even simple things
as age. I got my frustrations with nooblets over the years, all barging
in asking the same thing in the same demanding way; but let's face it -
neither of us is going to change this, and it will just make you bitter
and twisted, and give you ulcers in the end if you work yourself up over
these things.... so, for the sake of keeping LQ a friendly community,
and your personal well-being (as well as my time spent on moderation
rather than technical support), please tone it down.


Cheers,
Tink
 
1 members found this post helpful.
Old 08-05-2011, 09:57 PM   #8
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by afiqrahim View Post
Any little tips would do.
Well ok, I'll give you a few suggestions. First of all, read the Advanced Bash-Scripting Guide or perhaps another Bash tutorial on the net, there are plenty of those, just do a search.

In order to solve your problem, familiarize yourself with variables and how to assign values to them, so you can understand statements like this:

Code:
MESSAGE="Press '?' for help, 'q' for quit or enter your search terms: "
echo -n $MESSAGE
Read about loops, how they work and how to use them. This is a simple example of a while loop:

Code:
while true; do
   echo "it's true"
done
Have a look at the Bash manpage and read about the read command, you'll need that one to get user input in your script. Type "man bash" or "help read" for more information.

Study the Testing and Branching chapter and learn how to write a case statement. This will help you determine the value of a variable and perform actions based on that value. For instance:

Code:
case "$i" in
  q|Q) echo "Thanks for being here, come again."
       exit;;
esac
Finally, read the manpage for the find command: man find. This command will search for files based on the parameters you specify on the command line.

When you know and combine all these concepts, you'll be able to write your script. That should get you started. But next time, try to do a little research on your own, ask your instructor or search the web. And if you're really stuck, post again, ask smart questions, and people will help you.
 
Old 08-06-2011, 02:20 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by afiqrahim View Post
You're so provocative. I never ask you to practically DO my assignment. Any little tips would do. I already have the output. I just wanna brush it up a bit.
I did give you little tips. Told you to read up on the find command, gave you a link to a scripting tutorial site, and even told you what to look up ON that tutorial to do what you wanted.

You have OUTPUT of the script, and specifically asked if someone had "codes" on how to write a bash script to locate a files. You didn't post any of your work, and based on your question, it sure seemed like you were asking us to write it for you.
Quote:
It was my lecturer himself who asked me to ask questions from this page.
Really? Your teacher told you to come here and ask for a bash script?
 
  


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
question about shell-script programming GSX Programming 11 11-22-2005 04:58 PM
shell script programming problem newbie_ken Programming 5 08-16-2004 11:19 AM
shell script programming steltner Linux - General 0 05-17-2003 07:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:21 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