Raspberry Pi
NILUG Articles about the Raspberry Pi
Links to Raspberry Pi Information
NILUG Articles about the Raspberry Pi
Links to Raspberry Pi Information
Learning Linux is a tutorial concerning the choosing, installation and use of Linux.
The talk that Frank Ten Thy gave to the group on how to install and configure MythTV was excellent. He installed the Mythbuntu distribution on a computer and used the HDHomeRun tuner as its input. He brought along a set of rabbit-ears for an antenna and we could see that configuring for that tuner was a snap.
Frank then set up another box he had built and installed as a MythTV backend and frontend to show us how other media is handled by the program. He had imported several DVDs to the box and had recorded a bunch of television programs. They all played back flawlessly.
About half of our users group was all set to create a MythTV installation after seeing Frank do it, so that shows how well it was received.
Here are some links that are helpful if you are interested in finding out more about this.
The February meeting of the North Idaho Linux Users Group will be held on Saturday, 14 February at the River of Life Friends Church in Post Falls. The meeting will start at 1 pm.
We will have a topic for this month’s meeting, but we have not yet decided what the topic will be. Suggestions for future topics are welcome.
The NILUG meeting is free to all. If you would like to know more about Linux, or would like help installing Linux on your computer, we encourage you to attend the meeting.
Update (02/10/2009)
Topics for this month’s meeting:
This is fairly easy with Ubuntu 7.10 and later. This assumes you have your notebook set up to dual-boot both Ubuntu and Windows.
1. Tools to use
To write a shell script, use a standard text editor. That can be a command line editor, such as vi, emacs, pico, ted or joe. It can also be a GUI editor, such as Gedit, Kate, Kwrite, Kedit or Jedit.
Shell Scripts always start with a line telling the shell what program to use to execute the script. The line always starts with a shebang and the path to the program that will execute the script:
#!/bin/bash
#!/bin/sh
The first line would invoke the Bourne Again Shell. The second line would invoke the generic Bourne Shell.
2. Executing a shell script
Once a shell script file is written and saved, you must tell the the shell that it is actually executable, not just another text file. You do this by changing the file permissions:
chmod +x myscript.sh
chmod 755 myscript.sh
Both of the above commands set the myscript.sh file to be executable. If you have saved the file someplace where root access is required to change permissions, use
sudo chmod +x myscript.sh
sudo chmod 755 myscript.sh
To execute the script, you must tell the shell to run it.
myscript.sh # script is in the shell PATH
/tmp/myscript.sh # script is not anywhere known
./myscript.sh # script is in the current directory
If the file has been saved somewhere on the path (echo $PATH to see where the shell looks), then just typing the name of the shell script will execute it. If the file has been saved somewhere else, type the full path to the file. If the file is in the current directory, type a ‘./’ before the name.
3. Writing the script
A shell script just contains a list of commands you could just as well type directly on the command line. The commands can be external programs or internal shell commands. If the list is long or the commands are long, it is easier to put them in a script and execute the script with a single command. Here is a simple ‘hello.sh’ script:
1: #!/bin/bash
2: #
3: # hello.sh
4: #
5: clear
6: echo "Hello, $USER"
7: echo "Today is"
8: date
9: echo "This is an $HOSTTYPE machine"
10: echo "Number of users logged in:"
11: who | wc -l
12: echo "This month's calendar:"
13: cal
14: exit 0
Line 1 tells the command line shell to use bash to execute this script.
Since anything after a single # is considered a comment and is ignored, lines 2 through 4 are ignored.
Line 5 is a Linux command that is used to clear the terminal display.
All shells have certain ‘built-in’ commands. The echo command is one of those ‘built-ins’. It prints the line to the display. Line 6 uses the echo command to display the line. Note the $USER on this line. All shells also have items called ‘environment variables’. The USER variable is one that is always present. It contains the name of the person who is logged in. The $ is used to tell the shell that this is an environment variable and that we want to use its contents. If you want to see all the environment variables, just type ‘set’ (the ‘set’ command is used to display, set and clear the variables.)
Like line 6, line 7 echoes its contents.
Line 8 executes the Linux ‘date’ command to display the current date and time.
Lines 9 and 10 echo their contents.
Line 11 demonstrates how to pipe the output of one Linux command into the input of another Linux command. The ‘who’ command prints a line for each use logged in to the machine. Those lines are piped into the ‘wc -l’, where the wordcount program counts the number of lines (-l) and displays the result.
Line 12 echoes its contents.
Line 13 is a Linux command that displays a calendar. With no arguments, it will display a calendar for the current month.
Line 14 is optional, but a good idea to include. All shell scripts return a value to the shell they are running under. If that return value is zero, then everything has gone all right in the script. If it is any other value, it’s considered an error. If you don’t include the ‘exit’, the script will return the results of the last command executed (the ‘cal’ command in our example).
4. Shell Variables
When processing data in a script, it is often necessary to refer back to values created earlier in the script, or to values created by Linux itself. These values are stored in places called shell variables. Shell variables are untyped: they can be treated as either alphanumeric strings of characters or as numbers, depending on whether they actually ARE numbers.
Each variable has a label. That variable is invoked by the shell script by using the label with a dollar sign ($) pre-pended to the label. For instance, the PATH variable is used as $PATH. If you neglected to put that dollar sign in front, the shell script would assume you wanted to use the word PATH. Important note: shell variables are case-sensitive. PATH, Path and path are all different variables.
There are a lot of built-in shell variables other than the ones we have already mentioned. Here are a few more that may be of interest.
5. Built-in Commands
While the command shell can execute any program you tell it (and it can find), its real power comes from using commands that are built into the shell program. These internal commands allow you to do things like changing environment variables, sending information to the display, make other changes to the shell environment and, most importantly, control the flow of your shell program.
Some of the environment-type commands that are built into the shell are
The program flow commands are
Here is a simple iftest.sh script
1: #!/bin/bash
2: #
3: # iftest.sh
4: #
5: echo "What is your name?"
6: read yourname
7: if [ $yourname == "mike" ]; then
8: echo "Hey, $yourname, I know you!"
9: else
10: echo "Hello, $yourname, I'm happy to meet you."
11: fi
12: exit 0
We have already talked about lines 1 through 4 in our first example.
Line 5 is the prompt for user input.
Line 6 reads a line from the keyboard and puts it in the shell variable ‘yourname’.
Line 7 tests the contents of yourname against the string ‘mike’. if they are equal, line 8 is executed, then line 11. If the test is false, line 10 is executed, then line 11.
Line 12 is our normal exit from the program.
6. Towers of Hanoi Example (hanoi.sh)
The Towers of Hanoi program demonstrates the use of the case statement, subroutines and program recursion.
#! /bin/bash
#
# The Towers Of Hanoi
# Bash script
# Copyright (C) 2000 Amit Singh. All Rights Reserved.
# Modified by M. Burton
# http://hanoi.kernelthread.com
#
# Last tested under bash version 2.05b.0(13)-release
#
dohanoi() {
case $1 in
0)
;;
*)
dohanoi "$(($1-1))" $2 $4 $3
let "STEP=STEP + 1"
echo ${STEP}: move $2 "-->" $3
dohanoi "$(($1-1))" $4 $3 $2
;;
esac
}
STEP=0
case $# in
1)
case $(($1>0)) in
1)
dohanoi $1 1 3 2
exit 0;
;;
*)
echo "$0: illegal value for number of disks";
exit 2;
;;
esac
;;
*)
echo "usage: $0 N"
exit 1;
;;
esac
This is fairly easy with Ubuntu 7.10 and later. This assumes you have your notebook set up to dual-boot both Ubuntu and Windows.
SUPER+SHIFT+DRAG LEFT MOUSE = draw fire
SUPER+SHIFT+C = clear fire
CTRL+ALT+DRAG LEFT MOUSE = rotate cube
CTRL+ALT+LEFT ARROW = rotate cube
CTRL+ALT+DOWN ARROW = flat desktop
SHIFT+ALT+UP = initiate window picker
CTRL+ALT+DOWN = unfold cube
ALT+TAB = window switch
SUPER+TAB = flip switcher or ring switcher, depending on which is enabled.
ALT+F7 = initiate ‘move windows’
SHIFT+F9 = water effect
SHIFT+F10 = slow animations
CTRL+ALT+D = show desktop
For Grouping and Tabbing:
SUPER+S = select single window
SUPER+T = tab group
SUPER+Left = change left tab
SUPER+Right = change right tab
SUPER+G = group windows
SUPER+U = ungroup windows
SUPER+R = remove group window
SUPER+C = close group
SUPER+X = ignore group
Hold the SUPER button then select the windows you want to group and then hit SUPER+G.
The SUPER key is the Windows key on most keyboards.
NILUG was formed to spread the word to uninformed computer users in North Idaho and Eastern Washington about Linux, an Operating System that could replace their slow, buggy, cranky, proprietary operating system, and still allow them to perform all their work.
NILUG welcomes everyone, from complete beginners to experts. Topics discussed can range from the simple and obvious to the complex and arcane. Mostly, we just enjoy talking to others about Linux
You can become a member just by showing up at a meeting, or by joining our mailing list. We don’t ask for dues and we don’t release your email address to spammers. Join now – you may learn more than you really want to.
NILUG meets on the second Saturday of each month at 12:00 PM. Our meeting place is at Frank Ten Thy’s house.
The meetings include question and answer sessions, information desemination and working on projects. We hope to see you there.
Welcome to the new web site for the North Idaho Linux Users Group. We are in the process of restoring the content from the old web site, so please be patient with us. Thanks.
In the meantime, please note that the next meeting of NILUG is on Saturday, 2 December, 2006, 12 noon at Frank Ten Thy’s house. A map to the location is available here.