LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   New to linux and needs help> Thanks (https://www.linuxquestions.org/questions/linux-newbie-8/new-to-linux-and-needs-help-thanks-904409/)

laukman 09-22-2011 07:04 AM

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

Nylex 09-22-2011 07:09 AM

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").

David the H. 09-22-2011 10:17 AM

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. :twocents:

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. :study:

onebuck 09-22-2011 07:03 PM

Hi,

Welcome to LQ!
Quote:

Originally Posted by laukman (Post 4479090)
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. :)

chrism01 09-22-2011 09:05 PM

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/


All times are GMT -5. The time now is 03:06 PM.