BASH shell en: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Srugam (talk | contribs)
No edit summary
Srugam (talk | contribs)
Line 28: Line 28:


{|style="background:lightyellow;width:500px;margin:3px;border:1px solid lightgrey" align=centre
{|style="background:lightyellow;width:500px;margin:3px;border:1px solid lightgrey" align=centre
| style="padding:0px 0px 0px 80px;font-family:courier;font-size:8pt;" |touch textfile.txt
| style="padding:0px 0px 0px 80px;font-family:courier;font-size:8pt;" | sudo su student2
|}
|}


==Topics==
==Topics==

Revision as of 13:20, 7 May 2017

Using shell scripting to automate Linux maintenance tasks

Author

Translated from Estonian by Steven Rugam

Short introduction

Bash (Bourne-again shell) is a well-known shell. Bash scripts are used to simplify and automate system work. When talking about bash in few words, then the structure of the language and possible usages are being checked. At length, however, focus lies on the certain administrating assignments which are solved with bash scripting language.

Purpose

Providing skills for the bash scripting language to simplify and to improve efficiency towards our daily work.

Prerequisites/Assumptions

History with GNU/Linux operation system and acquired skills, which are being tested by automated self-test.

To test prerequisites, you should pass self-test.

Target group

Support engineers and system administrators.

Educational materials for learning BASH shell

Bash for the beginners

Additional learning materials

https://bash.cyberciti.biz/guide/Main_Page

Bash Configuration

Login Script

When bash is invoked, it runs /etc/profile if that file exists. Next, it looks for these files (in this order) ~/.bash_profile, ~/.bash_login , and ~/.profile. The first one that is found gets executed (any others are ignored). In the case of Ubuntu, ~/.profile is found and executed. (All of ~/.bash_profile, ~/.bash_login , and ~/.profile are ignored if --noprofile is used as an option to the underlying bash call). So for example, if you login via a virtual console, or if you change to another user e.g:

sudo su student2

Topics

  • Bash in general
    • What is bash and shell
    • Bash script writing
    • Executing bash scripts
  • Bash configuration files
    • .bash_profile: .bash_login ja .profile
    • .bashrc
    • .bash_logout
    • /etc/profile, /etc/profile.d/
    • Bash command history in .bash_history
  • Bash Syntax
    • Commenting
    • Symbols with special meaning(metacharacters, escaping characters, wildcards)
    • Difference between quotation marks and single quotation mark
    • Parameters
    • Catching user input and interactive scripts
    • Exit codes
    • Multiple commands on the same row
    • Piping
    • If sentences (if-else, case)
    • Cycles (for, while, until, select)
    • Control of strings (larger than, larger/smaller than or equal, smaller than)
    • File descriptors (stdin, stdout, stderr)
    • File existance scripts
    • Functions
    • Arithmetic operations, rounding
    • Regular expressions
    • Usage of arrays
  • Basics of bash
    • Utilities and their usage (echo, cat, cut, wc, sed, awk, mv, cp, mkdir, ls, file, head, uniq, tail, etc.)
    • Processes and executing them (ps, pstree, top, &)
    • Detecting shell script mistakes and fixing them

Example exercises

  • Calculation exercises
  • String manipulations
  • Exercises with files
  • Writing scripts, which show system configurations (logged in users, OS version, RAM info, Partitions etc)
  • Stopping processes and restarting processes
  • Adding new domains to DNS servers from the shell
  • Converting file lowercase characters to uppercase characters

Links

http://gnome-look.org/content/show.php/Ultimate+Bashrc+File?content=129746 hacking .bashrc

References