LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-08-2011, 11:23 AM   #1
kdx1980
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Rep: Reputation: Disabled
linux tutor's in southeast Michigan


I need a tutor for linux. I have spent countless hours struggling with writing very basic script shells and have come to realize this isnt what i am going be doing for a living. I cant seem to get the help I need from my teacher, book or the internet. I am a cisco major who had to take an intro to linux class. That has found out it is basically a programming class. I have no interest in writing script shells however I still need to pass the class. Im not looking for anyone to do my homework, but i do need some serious one on one help that i am willing to pay for. I live in southeast michigan and am willing to drive up to an hour. Thanks in advance
 
Old 08-08-2011, 01:25 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
For many Linux/UNIX concepts there are on line tutorials. There are quite a few for shell scripting.

For example this one for Linux shell scripting:
http://www.freeos.com/guides/lsst/

Scripting isn't really that hard so long as you remember that any series of commands you type at command line can be a script. For example if you wanted to see how much space was in your current filesystem you'd type "df -h .". To see what the permissions/ownership of the current directory are you'd type "ls -d ." To create a script that showed you both you can just edit a file and put those two commands in it:
Code:
df -h .
ls -d .
You then have to make the file executable (e.g. chmod 755 <filename>). Once you do that you can run the script by typing "./<filename>". You can run it in other directories by putting in full path (e.g. /home/mydir/<filename>). You can do it without typing in full path by adding the directory it is in to your PATH variable (e.g. PATH=$PATH:/home/mydr) then you can run <filename> without having to specify ./ or full path.

It really is that easy to make "a" shell script. There is generally more you should but don't HAVE to do. One example is that most scripts have an interpreter line that tells it what shell to use so the above script would be:
Code:
#!/bin/bash
df -h .
ls -d .
That tells it to use /bin/bash to run the commands that follow. (bash is the default shell on most systems but there are others and by adding this first line you insure that the script is always run as bash even if the users started in something else like dash, ksh or csh.)

Other things might be to do error checking and setting variables. The tutorial link (or any other you find) should go over this.

You may end up needing to know more about command line/scripting than you think. CISCO has its own shell scripting.

GUIs are nice but real admins use CLI and scripting.
 
1 members found this post helpful.
Old 08-08-2011, 01:45 PM   #3
kdx1980
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Maybe my scripts are harder than I thought because i get the commands I understand the permissions. The problem im having is how it all fits together. for instance, a part of my assignment was to write a program that shows and calculates a multiplication table 1-10 using a nested loop and use different options of the echo command to display the results. I found some examples that kind of helped me write the program however it wasnt a nested loop. I could not find anything like that. I have only been working with any kind of cli for 5 weeks, and some of these assignments do not seem very "intro" to me.
'
'
 
Old 08-08-2011, 01:50 PM   #4
sinuhe
Member
 
Registered: Apr 2010
Location: Utah
Distribution: Slackware
Posts: 53

Rep: Reputation: 9
Guru Labs

Guru Labs has a two day shell scripting course, which can be customized as needed.

http://www.gurulabs.com
 
0 members found this post helpful.
Old 08-08-2011, 02:25 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
For a nested loop you want to do something like:

Code:
#!/bin/bash
for x in 1 2 3
do echo Doing subroutine for $x
   for y in 4 5 6
   do echo Multiplying $x times $y
      expr $x \* $y
   done
done
What makes this "nested" is that you're doing one loop inside another. The first loop is acting on 1 then on 2 then on 3. When it acts on 1 it is multiplying 1 times 4 then times 5 then times 6. It then does the same thing by multiplying 2 times 4 then times 5 then times 6 and finally does it for 3.

You might want to set your expr command as a variable to be used in multiple echo statements required by your assignment so you aren't having to redo the calculation each time. Doing that is simple:

Code:
#!/bin/bash
for x in 1 2 3
do echo Doing subroutine for $x
   for y in 4 5 6
   do echo Multiplying $x times $y
      RESULT=$(expr $x \* $y)
      echo Result is $RESULT
   done
done
Note that variables (other than positional parameters and other special ones) are entirely arbitrary. The above script could be written as:
Code:
#!/bin/bash
for billybob in 1 2 3
do echo Doing subroutine for $billybob
   for suzyq in 4 5 6
   do echo Multiplying $billybob times $suzyq
      RalphieMay=$(expr $billybob \* $suzyq)
      echo Result is $RalphieMay
   done
done

Your various echo options can be determine by typing "man echo". (Note that bash has a built in echo command which is separate from the echo command the man page discusses - much of it is the same but if something doesn't work the way you'd expect you need to type "man bash" and go to the discussion it has for its internal echo to determine differences.) A common echo option is to put "\n" at the end of a what you're echoing to add a new line. There are other characters for tabs etc...

You can also find out what other commands do by using man page. (For example "man expr" will show you what the expr command is used for.)

P.S. Although I indented to make it clear where the nested loop starts and ends within the main loop this isn't required - it does however make it easier to read for a couple of levels of nesting - for more it might get unwieldy and you'd probably want to look at functions but hopefully that is something later in your class.

Last edited by MensaWater; 08-08-2011 at 02:27 PM.
 
1 members found this post helpful.
Old 08-08-2011, 02:40 PM   #6
kdx1980
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks!

Thank you for those examples. I believe with those examples I can probably muddle through it. Its funny that you mention functions because they are the next part of the assignment. this part will probably keep me busy the rest of the day. I hate begging you all for help, but at this point I dont know where else to turn. Thanks again

KDX1980
 
Old 08-08-2011, 03:04 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Some links that might help:

http://linuxcommand.org/writing_shell_scripts.php

http://mywiki.wooledge.org/BashPitfalls
 
Old 08-08-2011, 09:03 PM   #8
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,345
Blog Entries: 28

Rep: Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145
There are two excellent manuals at the Linux Documentation Project right towards the top of the linked page.

I have not reached the "Advanced" guide (and probably never will), I can attest to the Beginner's Guide. It's excellent.

According to this thread, there are some LUG's in southeast Michigan:

http://www.linuxquestions.org/questi...-in-mi-812514/
 
Old 08-09-2011, 02:06 AM   #9
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If you're looking for local people, you should look for a Linux User Group. Here is a list of some in Michigan. There may be others, so do some googling.

Also, you don't use apostrophes in plurals, so "tutor's" should be "tutors".
 
0 members found this post helpful.
Old 08-09-2011, 10:11 AM   #10
kdx1980
LQ Newbie
 
Registered: Aug 2011
Posts: 7

Original Poster
Rep: Reputation: Disabled
Yeah I guess the apostrophe would only be if you were referring to the tutor owning something. Lol. Thanks again for all your responses.
 
  


Reply



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
Calling all Southeast Connecticut Linux User jcookeman Linux User Groups (LUG) 2 06-20-2017 10:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:14 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
Open Source Consulting | Domain Registration