Proposal Student Competition Enhancement

Download Report

Transcript Proposal Student Competition Enhancement

Module 5 - Shell Overview

The Shell Environment

• Each shell is opened with a set of variables.

• Some of them are defined by the system and some are defined by the user.

• Environment variables set by the user will always be “stronger” then the variables set by the system.

How can we see the variables ?

• the

env

variables command lists all the system shell # env • the

set

command lists all the user environment variables # set

System Environment Variables

• two files reside under the /etc directory: 1.

bashrc 2.

profile

User Environment Variables

• Two files reside under the user home folder: 1.

.bashrc

2.

.bash_profile

The path variable

• •

Pre and Post Pathing

Linux determines the executable search path with the $PATH environment variable. • To add directory /ort/myscripts to the beginning of the $PATH environment variable, use the following: PATH=/ort/myscripts:$PATH • To add that directory to the end of the path, use the following command: PATH=$PATH:/ort/myscripts

Aliases

• • • An alias is nothing but shortcut to commands. The alias command allows user to launch any command or group of commands (including options and filenames) by entering a single word. Use the

alias

command to display list of all defined aliases. You can add user defined aliases to

~/.bashrc

file.

# alias

Aliases

• Aliases provide an excellent way to: • • • • Substitute a short command for a long one Create a single command for a series of commands Create alternate forms of existing commands Make command options default • Command format: # alias

aliasname=‘value’

• • To view your current aliases use the alias command without arguments To remove an alias use the unalias command: # unalias

aliasname

The history variable and command

• BASH shell keeps history of typed commands (The default is the last 1000 commands and can be set using the HISTSIZE bash variable).

• Commands history is saved into a file named ~/.bash_history

• • (this can be changed by setting HISTFILE variable) To display previously entered command type: # history [options] • history 3 will show the last 3 commands entered.

History

• The ! command enables users to re-execute commands from the history list • The command format is: ! [

argument(s)

] • The arguments that are passed to the ! command is the line number of a particular command, or a letter indicating the most recent command in the history list that start with that letter.

• Re-execution of the last command is possible using double exclamation marks – ‘!!’

Quoting in Shell

• • • Shell metacharacters usually have special meaning To cancel it, the characters must be quoted Three types of quoting exist: • ‘ ‘– single quotes cancel everything within them • “ “ – double quotes cancel everything but the $ character • \ - the back slash cancels that character immediately after it

Variables

• Use dollar sign ( $ ) to expand the value of a variable.

• • $ is a metacharacter meaning “

substitue with value

” The shell looks for the variable in the and replaces $

variablename

with the value of the variable.

• Setting a new variable is easy: • # ort=/tmp So the easier way to see a variable’s value is to type # echo $ort # cd $ort •

Important ! If you want the variable to be exported to subshell you need to export it: # export ort

Command substitution

• • • • Command substitution allows the output of a command to replace the command itself. Command substitution occurs when a command is enclosed as follows: ` $( or

command command

` ) # echo “my name is” $(whoami)

Adding a new user

• Adding a new user with the

useradd

command: # useradd hagay or with options: # useradd -d /tmp -c temp -g ort -p 123456 hagay

Adding a new Group

• Adding a new user with the

groupadd

command: # groupadd ort or with options: # groupadd -g 600 ort

The skel directory

• Under /etc reside the skel directory.

• The skel directory functions as a template for new user creation.

• everything in the skel directory will be duplicated to the new user environment.

Exercise

• • • Add a new user with the name

bibi

and password

bibi

Add a new group called

gov

use the

usermod

(read the man!) to change bibi default group to the

gov

group • • • • • (use the id command to check the result) Set a new variable with your name.

echo the new variable to the shell Set the variable as a permanent one in your user environment and export it.

Set a new and permanent alias that will clean the screen every time you type ort.

Add /tmp to your path