Shell Scripting, Part I Flashcards

1
Q

What does a SCRIPT contain?

A

contains a series of commands

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

What is an INTERPRETER?

A

executes commands in the script

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

What can you put in a script?

A

Anything you can type at the command line

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

What are Shell Scripts good for?

A

Automating tasks

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

What is #!

A

Sharp Bang (otherwise known as a “shebang”)

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

What follows a shebang #! ?

A

Whatever follows it is used as the interpreter

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

What if your script doesn’t contain a shebang?

A

Then commands are executed using your shell

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

What is chmod 755?

A

755 means read and execute access for everyone and also write access for the owner of the file. It’s the executable bitset.

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

What’s the difference?

#!/bin/csh
#!/bin/ksh
#!/bin/zsh
A

The scripts use different interpreters.

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

What are VARIABLES?

A

Storage locations that have a name.

  • Name-value pairs
  • Variables are CASE SENSITIVE
  • By convention variables are uppercase, don’t use any spaces between equal sign
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Are VARIABLES case sensitive?

A

YES!

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

What can variable names contain?

A

Letters, digits, and underscores, but can’t start with a digit. NO other special characters.

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

What is a TEST in a shell script?

A

A test allows you to test out a conditional expression to check for status.

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

What is the syntax for a TEST in a shell script?

A

[ condition-to-test-for ]

EXAMPLE:
[ -e /etc/passwd ]

WILL RETURN 1 or 0 (True or False)

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

How do you assign a command output to a variable in a shell script?

A

set it equal to $(command)

Example: SERVER_NAME=$(hostname)

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

How do you use a variable in a shell script?

A

use a $ (dollar sign) before the variable name, or enclose it with { } curly braces

EXAMPLE: echo “I like the $MY_SHELL shell”

EXAMPLE: echo “I like the ${MY_SHELL} shell.”

17
Q

What is -d FILE

A

True if file is a directory

18
Q

What is -e FILE

A

True if file exists

19
Q

What is -f FILE

A

True if file exists and is a regular file

20
Q

What is -r FILE

A

True if file is readable by you

21
Q

What is -s FILE

A

True if file exists and is not empty

22
Q

What is -w FILE

A

True if file is writable by you

23
Q

What is -x FILE

A

True if file is executable by you

24
Q

What is -z STRING

A

True if string is empty

25
Q

What is -n STRING

A

True if string is not empty

26
Q

What is STRING1 = STRING2

A

True if the strings are equal

27
Q

What is STRING1! = STRING2

A

True if the strings are not equal

28
Q

What is arg1 -eq arg2

A

True if arg1 is equal to arg2

29
Q

What is arg1 -ne arg2

A

True if arg1 is not equal to arg2

30
Q

What is arg1 -lt arg2

A

True if arg1 is less than arg2

31
Q

What is arg1 -le arg2

A

True if arg1 is less than or equal to arg2

32
Q

What is arg1 -gt arg2

A

True if arg1 is greater than arg2

33
Q

What is arg1 -ge arg2

A

True if arg1 is greater than or equal to arg2