105 Shells and Shell Scripting KT Flashcards

1
Q

105.1 Customize and use the shell environment

A

The following is a partial list of the used files, terms and utilities:

.
source
/etc/bash.bashrc
/etc/profile
env
export
set
unset
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
~/.bash_logout
function
alias
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

.

A

Command: Read and execute commands from the filename argument in the current shell context.

. filename [arguments]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

source

A

Command: Read and execute commands from the filename argument in the current shell context. source is a synonym for dot/period ‘.’ in bash, but not in POSIX sh, so for maximum compatibility use the period.

source filename [arguments]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

/etc/bash.bashrc

A

System‐wide .bashrc file for interactive non-login shells.

The Debian version of bash is compiled with a special option (-DSYS_BASHRC) that makes bash read /etc/bash.bashrc before ~/.bashrc for interactive non-login shells. So, on Debian systems, /etc/bash.bashrc is to ~/.bashrc as /etc/profile is to ~/.bash_profile.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

/etc/profile

A

/etc/profile: system‐wide .profile file for the Bourne shell.

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

env

A

Command: Set each NAME to VALUE in the environment and run COMMAND. Run a program in a modified environment.

env [OPTION]… [-] [NAME=VALUE]… [COMMAND [ARG]…]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

export

A

Command: Set export attribute for shell variables. Marks each NAME for automatic export to the environment of subsequently executed commands. If VALUE is supplied, assign VALUE before exporting.

export [-fn] [name[=value] …]
export -p

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

set

A

Command: Set or unset values of shell options and positional parameters. Change the value of shell attributes and positional parameters, or display the names and values of shell variables.

set [-abefhkmnptuvxBCHP] [-o option-name] [–] [arg …]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

unset

A

Command: Unset values and attributes of shell variables and functions. For each NAME, remove the corresponding variable or function.

unset [-f] [-v] [-n] [name …]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

~/.bash_profile

A

The ~/.bash_profile file is a configuration file for configuring user environments. The users can modify the default settings and add any extra configurations in it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

~/.bash_login

A

The ~/.bash_login file contains specific settings that are executed when a user logs in to the system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

~/.profile

A

The ~/.profile file is yet another configuration file that is read in the absence of the ~/.bash_profile and ~/.bash_login files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

~/.bashrc

A

User specific .bashrc file. ~/.bashrc: read and executed by bash(1) for interactive non‐login shells.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

~/.bash_logout

A

The ~/.bash_logout file contains instructions for the logout procedure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

function

A

Command: This builtin command is used to create a new function. A function is a list of commands that will be executed when the name of the function is entered.

function [OPTIONS] NAME; BODY; end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

alias

A

Command: An alias definition provides a string value that shall replace a command name when it is encountered.

alias [alias-name[=string]…]

17
Q

105.2 Customize or write simple scripts

A

The following is a partial list of the used files, terms and utilities:

for
while
test
if
read
seq
exec
||
&&
18
Q

for

A

A for loop is classified as an iteration statement i.e. it is the repetition of a process within a bash script.

for VARIABLE in 1 2 3 4 5 .. N
do
	command1
	command2
	commandN
done
19
Q

while

A

he bash while loop is a control flow statement that allows code or commands to be executed repeatedly based on a given condition.

while [ condition ]
do
   command1
   command2
   command3
done
20
Q

test

A

Exit with the status determined by EXPRESSION. Check file types and compare values. test is the same as [.

test EXPRESSION
test
[ EXPRESSION ]
[ ]
[ OPTION
21
Q

if

A

if statements enable different courses of action to be taken in a shell script, depending on the success or failure of a condition.

if [ ]
then

fi

22
Q

read

A

Reads a single line from the standard input, or from file descriptor FD if the -u option is supplied.

read [-ers] [-a array] [-d delim] [-i text] [-n nchars]
[-N nchars] [-p prompt] [-t timeout] [-u fd] [name …]

23
Q

seq

A

Print numbers from FIRST to LAST, in steps of INCREMENT.

seq [OPTION]… LAST
seq [OPTION]… FIRST LAST
seq [OPTION]… FIRST INCREMENT LAST

24
Q

exec

A

Execute COMMAND, replacing this shell with the specified program.

exec [-cl] [-a name] [command [arguments …]]
[redirection …]

25
Q

||

A

|| will evaluate the right side only if the left side exit status is non-zero (i.e. false).

[ Eval 1 || Eval 2 ]

26
Q

&&

A

The right side of && will only be evaluated if the exit status of the left side is zero (i.e. true)

[ Eval 1 && Eval 2 ]