LinuxQuestions.org
Review your favorite Linux distribution.
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 12-28-2005, 12:45 AM   #1
mral
LQ Newbie
 
Registered: Dec 2005
Posts: 12

Rep: Reputation: 0
Help writing shell program


I'm trying to write a shell program reversey that will output the arguments passed to it in reverse order on a single line. Does anyone know of a good site that might help me accomplish this? Thanks.
 
Old 12-28-2005, 01:13 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Sounds like a homework assignment.

SUGGESTION:
1. Google for keywords like "linux, shell, programming, howto". I presume you also have a textbook and/or course notes.

2. Figure out how to find out the #/arguments into your script (hint: it's the special variable "$#").

3. Figure out how to print each of the arguments. In a loop. (hint: it'll probably involve the "shift", "while" and "expr" commands).

Finally,

4. Print the arguments in reverse order.
 
Old 12-28-2005, 01:29 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Read the output of "help for" in the bash shell to learn about for loops.
You can get the length of an argument using the form: ${#argument}.
Also, in the bashref menual, look at variable substitutions of the form ${variable:index:count}
 
Old 12-28-2005, 02:13 AM   #4
mral
LQ Newbie
 
Registered: Dec 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for the info.
 
Old 12-28-2005, 03:47 AM   #5
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware 14.1 (32 and 64 bit)
Posts: 1,594

Rep: Reputation: 124Reputation: 124
Reading your first posting I had the idea that you might want to get a bash scripting tutorial!? If you look at http://www.tldp.org/ you can find at least two texts that can give you more in-depth information:

The Bash Guide for beginners: http://www.tldp.org/LDP/Bash-Beginners-Guide/
Advanced Bash-Scripting Guide: http://www.tldp.org/LDP/abs/

Another source to start with bash scripting is Paul Sheers rute tutorial. It provides not so many details but some fundamentals (as well as other very useful information about Linux systems): http://rute.2038bug.com/index.html.gz
 
Old 12-29-2005, 03:07 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
But remember - anything you write in "bash" is probably non-portable to other *nix environments. I'd encourage you - at least for starters - to try to focus on the Bourne shell. It's easier to learn, and your scripts will arguably be simpler and more portable.

Once you're comfortable with scripting, only then would I encourage you to learn the (additional) Bash features.

IMHO .. PSM
 
Old 12-29-2005, 09:26 PM   #7
mral
LQ Newbie
 
Registered: Dec 2005
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks again.
 
  


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
shell script writing ust Linux - General 6 01-24-2005 02:06 PM
writing own shell bahuguna_n Programming 9 11-25-2003 03:11 PM
Writing C++ Shell Scripts MasterKin8T Programming 5 09-29-2003 11:43 AM
Need Help in Writing a Shell Script. KptnKrill Linux - General 2 05-19-2003 06:44 AM
writing a shell hopeless Programming 9 09-04-2002 09:28 AM


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