LinuxQuestions.org
Help answer threads with 0 replies.
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 05-02-2012, 09:17 AM   #1
arungala
LQ Newbie
 
Registered: May 2012
Posts: 19

Rep: Reputation: 0
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
 
Old 05-02-2012, 09:24 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
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.
 
Old 05-02-2012, 09:34 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,415

Rep: Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770
I recommend you start doing the homework. A better (answerable) question will occur to you once you do.
 
Old 05-02-2012, 09:37 AM   #4
arungala
LQ Newbie
 
Registered: May 2012
Posts: 19

Original Poster
Rep: Reputation: 0
thank you guys..its ok its apppearing on google..

can anyone tell how is it done using Bash scripting
 
Old 05-02-2012, 09:44 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
it's appearing on google??? huh??

No, we can't. Go learn something for yourself.
 
Old 05-02-2012, 11:05 AM   #6
arungala
LQ Newbie
 
Registered: May 2012
Posts: 19

Original Poster
Rep: Reputation: 0
i mean its ok if the question appears on google...actually i wasted 4 hrs on it and developed a headache...pls help
 
Old 05-02-2012, 11:10 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,492

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
So what do you have so far, and what is it doing/not doing?
 
Old 05-02-2012, 11:33 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,899

Rep: Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262Reputation: 4262
Quote:
Originally Posted by arungala View Post
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.
 
Old 05-02-2012, 11:42 AM   #9
arungala
LQ Newbie
 
Registered: May 2012
Posts: 19

Original Poster
Rep: Reputation: 0
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
 
Old 05-02-2012, 11:51 AM   #10
arungala
LQ Newbie
 
Registered: May 2012
Posts: 19

Original Poster
Rep: Reputation: 0
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
 
Old 05-02-2012, 11:53 AM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,492

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
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

Last edited by suicidaleggroll; 05-02-2012 at 11:55 AM.
 
Old 05-02-2012, 11:53 AM   #12
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 6,676

Rep: Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912Reputation: 1912
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.
 
1 members found this post helpful.
Old 05-02-2012, 11:54 AM   #13
arungala
LQ Newbie
 
Registered: May 2012
Posts: 19

Original Poster
Rep: Reputation: 0
its not possible to go through all this in one nite....i have to subit tomo
 
Old 05-02-2012, 11:57 AM   #14
jkirchner
Member
 
Registered: Apr 2007
Location: West Virginia
Distribution: LinuxMint
Posts: 775

Rep: Reputation: 199Reputation: 199
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
 
1 members found this post helpful.
Old 05-02-2012, 11:57 AM   #15
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: Slackware
Posts: 7,415

Rep: Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770Reputation: 2770
Quote:
Originally Posted by arungala View Post
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.

Last edited by dugan; 05-02-2012 at 02:28 PM.
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash scripting question, homework related cybergeek11235 Linux - General 4 10-12-2008 10:59 PM


All times are GMT -5. The time now is 05:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration