LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2011, 08:04 AM   #1
laukman
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
New to linux and needs help> Thanks


hi evry1.. today at campus we had tp just type in sum stuff in shell scripting. but i dont know what is happening. Sp could some1 please expalin each line of coding for me thanks.
the shell script is:
for i in 1 2 3
do
sort file${i} > newFile${i}
if [ ! -e "file${i}" ]
then
echo "file${i} does not exist."; echo
continue
fi

done
for x in 1 2 3
do
tail -1 newFile${x} >> out1
done
sort -r out1 > assmnt
rm newFile1 newFile2 newFile3 out1
 
Old 09-22-2011, 08:09 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
First of all, please use decent thread titles that describe your question/problem. Saying that you need help is not useful. It's better to say what you need help with.

Secondly, please write out your words in full.

Thirdly, when posting code here, put it between [code] tags to preserve indentation and aid readability.

Surely if you're learning shell scripting in a class, they must give you some resources or something to read? Have you consulted that material? You might also want to look at this.

For the commands used (e.g. sort and tail), look at their man pages to see what they do and how you can use them (e.g. "man sort").

Last edited by Nylex; 09-22-2011 at 08:10 AM.
 
Old 09-22-2011, 11:17 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
No, I don't think we're interested in breaking it down line by line for you. You'll learn more by working it out yourself.

But to give you a starting point, your script uses the following shell built-in features:

variables
for loops
if statements
[ tests
echo
continue
> and >> file redirections

And the following external commands:

sort
tail
rm

So once you know how each of these things works, you should be able to decode the script.

I highly recommend reading through this guide. It covers all the basic concepts.
http://mywiki.wooledge.org/BashGuide

Then if there are any specific points that you still don't understand, we'll be happy to help you out with them.
 
Old 09-22-2011, 08:03 PM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Welcome to LQ!
Quote:
Originally Posted by laukman View Post
hi evry1.. today at campus we had tp just type in sum stuff in shell scripting. but i dont know what is happening. Sp could some1 please expalin each line of coding for me thanks.
the shell script is:
Code:
for i in 1 2 3
do
 sort file${i} > newFile${i} 
 if [ ! -e "file${i}" ]
 then
  echo "file${i} does not exist."; echo
  continue
 fi
  
done
for x in 1 2 3
do
 tail -1 newFile${x} >> out1
done
sort -r out1 > assmnt
rm newFile1 newFile2 newFile3 out1
Notice in the quote above how the list is presented now. In the reply window you can insert between the
Code:
info here
tags to make your post cleaner therefore easier to read. You will find the # (code tags) at the top right of the reply windows which is the code tag that you can wrap around high lighted text. For quotes please use the balloon to the left of # which is for QUOTES.

LQ Rules state;
Quote:
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
We will help you but not carry you.

FYI: Netiquette is a set of social conventions that facilitate interaction over networks, ranging from Usenet and mailing lists to blogs and forums.


FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem or query. Plus it is a very helpful reference to formalize your question and Subject title.

Here at LQ we frown upon someone who cannot use full text and complete sentences. No SMS or tech speak!
LQ is a world community so we can understand when someone has a problem forming good understandable communication when English is not the first language.

If English is not your first language then I suggest that you learn to use a translator.

BTW, LQ has a good spell checker.
 
Old 09-22-2011, 10:05 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
1. consult your class docs
2. ask your teacher
3. read http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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




All times are GMT -5. The time now is 12:49 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration