Module 11: Basic scripting Flashcards

(56 cards)

1
Q

What is a shell script?

A

A file of executable commands that has been stored in a text file

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

Which text editor is used? What command?

A

Nano
Command: nano with script name
Nano test.sh

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

How to write a script?

A

Nano command
To get into the text editor

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

How to write a script inside text editor

A

Start with #! /bin/sh or bash
And then write the commands you want the script to do

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

How to search the document

A

Control and W

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

What are variables?

A

Holds temporary information in the script

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

What are conditionals?

A

It lets you do different things based on tests you write

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

What are loops

A

Let’s you do the same thing over and over

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

How to assign a variables

A

VARIABLE NAME = “value”
No spaces in between
To include the name, it should precede a $ sign

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

What is the read command?

A

Can accept a string right from the keyboard or as part of command redirection

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

How to create a new file with vi editor?

A

Vi filename

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

When I you create a new file, what should you type to go in insert mode?

A

i

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

How to exit insert mode and quit?

A

Esc key
Type :wq to write file and quit

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

Which key moves line up and down in command mode?

A

J goes down and k goes up

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

Which command moves right and left when in command mode

A

L moves right and h moves left

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

Which command moves cursor to the beginning and end of word

A

W moves to the beginning of word and e moves to the end of word

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

Which command moves cursor to beginning of previous word?

A

B

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

How to delete a word

A

Using the dw command

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

How to undo a last operation

A

Using the u command

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

How to delete two words?

A

2dw

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

How to delete characters at a time

A

Using x
Example: xxxx

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

How to undo last four operations

A

4u

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

How to delete 14 characters

24
Q

How to delete characters from the left

A

Capital X
Ex:
5X

25
How to delete a current line
dd
26
How to paste a deleted line
command p
27
28
How to move to a word and delete from current position to the end of the line
number(w) D Example: 4w D
29
How to join two lines?
command J
30
How to copy the current word
yw command
31
What does this command do: :%s/ext //g
Searches for the word text and deletes it
32
How to open a blank line
o command
33
How to open a blank line above the current line
Capital O
34
how to change word
cw
35
How to add text at beginning of a line
Using capital I
36
How to add text at the end of a line
Upper case A
37
What to always include at the beginning when creating a shell script
Shebang #!/bin/bash
38
What is chmod command used for?
To change permissions on the file so that the file can be executed
39
What is the test command
Compares two numbers or strings for things like equal to less than etc
40
What does the seq command do?
Can generate a list of integer value if you run it with the for loop
41
What is the correct way to save the current directory to a variable?
A= `pwd`
42
How to assign the result of a command to a variable?
Using back ticks VAR=`command`
43
How do you assign a current directory to a variable?
CURRENT=`pwd`
44
What does $1 represent in a script
The first argument passed to the script
45
What does $0 represent in a script?
The name of the script
46
What does exit code of 1 mean?in grep
String not found error
47
What does exit code of 0 mean
Success/OK
48
How do you check the exit status of the last command?
$?
49
What is the basic structure of an if statement in Bash?
If command; then fi
50
What does this do: if grep -q root /etc/passwd; then
Checks if root is in /etc/passwd
51
What does test -f path check?
If a file exist
52
What does test -d /path check
If a directory exist
53
What does test ! -f /path do?
If a file does not exist
54
What does test 1 -eq 1 mean
Numeric equality returns 0 if true
55
What does -ne mean in test 1 -ne 2
Numeric inequality
56
What is square bracket used for
An alias for test