http://www.ibm.com/developerworks/cn/linux/newto/index.html#10
Bash by example, Part 1: http://www.ibm.com/developerworks/linux/library/l-bash.html
=== Casual Note ===
Define:
$ myvar='This is my environment variable!'
Notice:
* 1. there is no space on either side of the "=" sign
* 2. No double quotes instead of single quotes: disables a bash feature called expansion
Use:
$ echo $myvar
This is my environment variable!
=== home work ===
* 1. create a derectory: mkdir
* 2. create a file: touch
* 3. edit the file and insert the content:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *myenvvar=getenv("EDITOR");
printf("The editor environment variable is set to %s\n",myenvvar);
}
to myvar.c
* 4. Save the above source into a file called myenv.c, and then compile it by issuing the command:
$ gcc myenv.c -o myenv
=== vi editor ===
* 1. vi command: vi text.txt
* 2. type "i" key: switch to edit mode
* 3. "shift+:" : switch to command mode
* 4. set line number: "shift+:" + "set nu"
* 5. save file: "ESC"-->"shift+:"-->"W" + "Enter"
* 6. quit: "shift+:" + q
=== wirte and run a shell ===
* 1. write a shell: myvar.sh
#!/bin/bash
# $1 is the first command-line argument to the script
# "${1##*.}" will remove the longest match of "*." from the beginning of the string
if [ "${1##*.}" = "tar" ]
then
echo This appears to be a tarball.
else
echo At first glance, this does not appear to be a tarball.
fi
* 2. run shell: type "chmod 755 mytar.sh" to make it executable
* 3. ./mytar.sh thisfile.tar
Bash by example, Part 1: http://www.ibm.com/developerworks/linux/library/l-bash.html
=== Casual Note ===
Define:
$ myvar='This is my environment variable!'
Notice:
* 1. there is no space on either side of the "=" sign
* 2. No double quotes instead of single quotes: disables a bash feature called expansion
Use:
$ echo $myvar
This is my environment variable!
=== home work ===
* 1. create a derectory: mkdir
* 2. create a file: touch
* 3. edit the file and insert the content:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char *myenvvar=getenv("EDITOR");
printf("The editor environment variable is set to %s\n",myenvvar);
}
to myvar.c
* 4. Save the above source into a file called myenv.c, and then compile it by issuing the command:
$ gcc myenv.c -o myenv
=== vi editor ===
* 1. vi command: vi text.txt
* 2. type "i" key: switch to edit mode
* 3. "shift+:" : switch to command mode
* 4. set line number: "shift+:" + "set nu"
* 5. save file: "ESC"-->"shift+:"-->"W" + "Enter"
* 6. quit: "shift+:" + q
=== wirte and run a shell ===
* 1. write a shell: myvar.sh
#!/bin/bash
# $1 is the first command-line argument to the script
# "${1##*.}" will remove the longest match of "*." from the beginning of the string
if [ "${1##*.}" = "tar" ]
then
echo This appears to be a tarball.
else
echo At first glance, this does not appear to be a tarball.
fi
* 2. run shell: type "chmod 755 mytar.sh" to make it executable
* 3. ./mytar.sh thisfile.tar