LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash scripting homework question (https://www.linuxquestions.org/questions/linux-newbie-8/bash-scripting-homework-question-942925/)

arungala 05-02-2012 10:17 AM

bash scripting homework question
 
Write a shell script to reverse the set of numbers given in command line except the last argument.
Display the last argument as it is in the end. See the output to get more details.
The script can take any number of arguments as input.


$ ./revbutlast.sh 1 2 3 4 5
The output is 4 3 2 1 5


$ ./revbutlast.sh 4 3 2 1
The output is 2 3 4 1

$ ./revbutlast.sh
./revbutlast.sh expects arguments

$ ./revbutlast.sh 1
The output is 1

---

Without using any loop like while, for
write the script and name it as revbutlast_withoutloop.sh

acid_kewpie 05-02-2012 10:24 AM

haha, nice.

this is not urgent for us at all.

you've not said please or thank you

you've not even tried to hide that it's homework, and copied it verbatim.

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

dugan 05-02-2012 10:34 AM

I recommend you start doing the homework. A better (answerable) question will occur to you once you do.

arungala 05-02-2012 10:37 AM

thank you guys..its ok its apppearing on google..

can anyone tell how is it done using Bash scripting

acid_kewpie 05-02-2012 10:44 AM

it's appearing on google??? huh??

No, we can't. Go learn something for yourself.

arungala 05-02-2012 12:05 PM

i mean its ok if the question appears on google...actually i wasted 4 hrs on it and developed a headache...pls help

suicidaleggroll 05-02-2012 12:10 PM

So what do you have so far, and what is it doing/not doing?

TB0ne 05-02-2012 12:33 PM

Quote:

Originally Posted by arungala (Post 4668615)
i mean its ok if the question appears on google...actually i wasted 4 hrs on it and developed a headache...pls help

Spell out your words. And do you really expect us to believe that you spent 4 hours searching on Google, and did not come across ONE bash scripting tutorial???

Since you're too lazy to even TRY to do your own homework or search for anything, I'll spoon-feed you a link:
http://tldp.org/LDP/abs/html/

There. Should be AMPLE information to help you write your own shell script. Otherwise, as others have said, post what YOU have written so far, and tell us where you're stuck, and we will HELP you. You will NOT find anyone here to do your work for you, though.

arungala 05-02-2012 12:42 PM

ACtually it is prohibited to use any loops...and i'm stuck as in if i take 5 aregments...how will sort them or where to start

arungala 05-02-2012 12:51 PM

i'm just a beginner and trying hard...its just a week since i touched shell scripting...working in a small company where i was given ths assignment..i finished many programs on my own....regarding this one if i get hint also,it wil help a lot

suicidaleggroll 05-02-2012 12:53 PM

Who said anything about using loops?

Where are you stuck? You need to tell us where you're at, we are not going to write this for you, nor hold your hand through the process. We will provide advice about specific problems you run into while YOU write the script.

Start here:
http://tldp.org/LDP/abs/html/interna...es.html#APPREF

273 05-02-2012 12:53 PM

I read your initial post and, due to very little linux scripting experience, wasn't even sure it was possible to do without a loop.
So I thought about what might be possible and googled and guess what? I wrote a script to do it and learned some bash in the process. It was quite fun.
Your teacher set you this so you would learn commands. Those hours on google were only wasted if you learned nothing.
Share what you have done, and what you know, and somebody may help. It helps nobody if someone writes this for you.
I'll give you a tip: learn about different ways to access arguments within scripts.

arungala 05-02-2012 12:54 PM

its not possible to go through all this in one nite....i have to subit tomo

jkirchner 05-02-2012 12:57 PM

They have asked you many times, post what you have done so far and show where you are stuck. Ask specific questions about where you are stuck

dugan 05-02-2012 12:57 PM

Quote:

Originally Posted by arungala (Post 4668649)
its not possible to go through all this in one nite....i have to subit tomo

That's too bad for you.

However, if you post what you came up with in those four hours, we might be able to help with that.


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