Scripting Flashcards

1
Q

What should the first line of the script file contain

A
#!/bin/bash - bourne again shell
a path to the shell that will be used to execute the script
#!/bin/sh - bourne shell
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how to check for conditional logic within a script

A
if [ a = b ] 
then
  #do something
else
  #do something else
fi
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how to pass args to a script

A

./scriptFile.sh arg1 arg2

……………
scriptFile.sh contents
#!/bin/bash

echo here is the value of the first arg: $1
echo here is the value of the second arg: $2

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

how to stop a script execution

A

exit

remember scripts can have an exit or return value that is a numeric type from 1 to 255. This is useful for passing error values to the calling process. Usually a success will return 0.

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

how to create and use variables

A

pi=”pig”
echo $pi is my fav animal

#can also use 
let pi="pig"
#spaces are a big no-no
pi = "pig" is invalid
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

is this valid for a variable declaration/assignment

variable = “New Variable”

A

It is not valid. The spaces will cause the line to error.
It should be:
variable=”New Variable”

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