Section 21+22: Scripts Flashcards

1
Q

Bash:

Comment
Variables
Arrays

A

o Comment
▪ # This is the first line of my script
▪ # This script is used to do backups of my systems

o Variables
▪ variable = value
CustomerName = Jason
$CustomerName
▪ declare option VariableName = value
declare -i PhoneNumber = 1111111
declare -r Pi = 3.14

o Arrays
▪ tempArray = (value1, value2, value3)
tempArray[position]
$tempArray[1] => value2

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

Bash:

Comparisons

A

Arithmetic
● is equal to
o if [ “$a” -eq “$b” ]
● is not equal to
o if [ “$a” -ne “$b” ]
● is greater than
o if [ “$a” -gt “$b” ]
● is greater than or equal to
o if [ “$a” -ge “$b” ]
● is less than
o if [ “$a” -lt “$b” ]

String Comparison
● is equal to
o if [ “$a” = “$b” ]
if [ “$a” == “$b” ]
● is not equal to
o if [ “$a” != “$b” ]
● is less than (in ASCII alphabetical order)
o if [ “$a” < “$b” ]
if [[ “$a” < “$b” ]]
● is greater than (in ASCII alphabetical order)
o if [ “$a” > “$b” ]
if [[ “$a” > “$b” ]]

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

Bash:

Inputting and Outputting Data

A

echo “Please enter your name:”
read UserName
echo “Hello $UserName!”

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

Powershell:

Comments
Variables
Arrays

A

Comment
▪ # This is the first line of my script
▪ <#
This is a comment block. You can use this to comment out large sections
of text or code in your scripts.
#>

o Variables
▪ $variable = value
$CustomerName = Jason
▪ [int]$AnswerNumber = 42
▪ [string]$AnswerString = “The life, the universe, and everything.”
▪ To declare a constant, simply make the variable read only
● Set-Variable Pi -Option ReadOnly -Value 3.14159

o Arrays
▪ Allows for the storage of multiple values and reference them from a
single name
▪ $tempArray = @()
$tempArray = @(‘Jason’, ‘Sahra’, ‘Eduardo’, ‘Linda’)
$tempArray[position]
$tempArray[1] => Sahra

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

Powershell:

Comparisons

A

Comparisons
▪ is equal to
● $a -eq $b
▪ is not equal to
● $a -ne $b
▪ is greater than
● $a -gt $b
▪ is greater than or equal to
● $a -ge $b
▪ is less than
● $a -lt $b
▪ is less than or equal to
● $a -le $b

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

Powershell:

Inputting/Outputting Data

A

Inputting and Outputting Data
▪ Write-Host “Please enter your name:”
Read-Host $UserName
Write-Host “Hello ” + $UserName + “!”

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

Powershell:

Reading and Writing Data into Files

A

Reading and Writing Data into Files
▪ $TempFile = Get-Content - Path C:\test.txt
Write-Host $TempFile
▪ Write-Host “This is the beginning of a new script log file” > script.log
▪ < means input, > means output
▪ > overwrites,&raquo_space; appends
● .\enumerate.ps1&raquo_space; script.log

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

Bash:

Reading and Writing Data into Files

A

Reading and Writing Data into Files
▪ TempFile=$(<filename)
▪ TempFile=$(<test.txt)
echo “$TempFile”
▪ < means input, > means output
▪ > overwrites,&raquo_space; appends
● echo “This is now going to be added to the end of the file as the
next line”&raquo_space; test.txt

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

Python:
Inputting and Outputting Data
Reading and Writing Data into Files

A

Inputting and Outputting Data
▪ userName = input(“Please enter your name:”)
print(“Hello ” + userName + “!”)

o Reading and Writing Data into Files
▪ tempFile = open(‘test.txt’, ‘w’) # write will overwrite any existing content
▪ tempFile = open(‘test.txt’, ‘a’) # append to the end without overwriting
▪ tempFile = open(‘test.txt’, ‘r’) # reads a file
▪ print(tempFile.read())
▪ print(tempFile.read(50)). # this would read the first 50 characters in the
file
▪ print(tempFile.readline(-5)). # this would read the last 5 lines of the file

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

Python:

Comment
Variables
Arrays

A

Comment
▪ # This is the first line of my script
▪ # This script is used to do backups of my systems

o Variables
▪ variable = value
Price = 10
▪ Integer variable doesn’t use quotes around the value
▪ String variables use quotes around letters and numbers
▪ Vendor = “CompTIA”
Vendor = ‘CompTIA’
Vendor = “123”
▪ Price = int(42)
Price = float(42.00)
Price = str(“The life, the universe, and everything.”)
▪ Type the variable name to display or interact with that variable
▪ In Python, constants aren’t really used like in other languages
▪ By convention, uppercase words are treated as constants and lowercase
or title case words as variables

o Arrays
▪ tempArray = []
tempArray = [value1, value2, value3]
nameArray = [“Jason”, “Mary”, “Joe”, “Susan”]
tempArray[position]
nameArray[0] => Jason

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

Python: Comparisons

A

Comparisons
▪ is equal to
● a == b
▪ is not equal to
● a != b OR a <> b
▪ is greater than
● a > b
▪ is greater than or equal to
● a >= b
▪ is less than
● a < b
▪ is less than or equal to
● a <= b

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

Perl:

Comment
variables
Arrays

A

Comment
▪ # This is the first line of my script
▪ # This script is used to do backups of my systems

o Variables
▪ $variable = value;
$CustomerName = Jason;
$CustomerName
▪ There is no need to declare variable types in Perl
▪ use constant NAME => <value>;</value>

o Arrays
▪ @tempArray = (value1, value2, value3);
@ages = (18, 21, 25, 30);
@names = (“Jason”, “Susan”, “David”, “Tamera”);
$tempArray[position]
$names[3] => Tamera

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

Perl:

Comparisons

A

Comparisons
▪ Numeric
● is equal to
o if ($a == $b)
● is not equal to
o if ($a != $b)
● is greater than
o if ($a > $b)
● is greater than or equal to
o if ($a >= $b)
● is less than
o if ($a < $b)
● is less than or equal to
o if ($a <= $b)

▪ String Comparison
● is equal to
o if ($a -eq $b)
● is not equal to
o if ($a -ne $b)
● is greater than
o if ($a -gt $b)
● is greater than or equal to
o if ($a -ge $b)
● is less than
o if ($a -lt $b)
● is less than or equal to
o if ($a -le $b)

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

Perl:

Inputting/Outputting Data
Reading/Writing Data to Files

A

Inputting and Outputting Data
▪ printf(“Please enter your name:”);
$string = <STDIN>;
printf(“You entered: $string”);</STDIN>

o Reading and Writing Data into Files
▪ open(DATA1, “<read.log”);
open(DATA2, “>write.log”);
▪ > overwrites,&raquo_space; appends
▪ while (<DATA1>) {
p</DATA1>

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

JavaScript:

Comment
Variables
Arrays

A

Comment
▪ // This is the first line of my script
▪ /*
This is a multi-line
comment block
*/
o Variables
▪ let variable = value;
let CustomerName = ‘Jason’;
CustomerName = ‘Dion’;
▪ const PI = 3.14159

o Arrays
▪ let tempArray = [value1, value2, value3);
let listOfNames = [‘Jason’, ‘Mary’, ‘Christle’, ‘Tim’];
listOfNames[position]
listOfNames[1] => Mary
▪ var myPhoneBook = {};
var myPhoneBook = {Jason: 111-1234,
Mary: 222-5678};
▪ myPhoneBook.Jason
myPhoneBook.Jason = 333-1234;
myPhoneBook[“Jason”] = 333-1234;

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

JavaScript:

Comparisons

A

Comparisons
▪ is equal to
● (num1 = num2)
▪ is not equal to
● (num1 != num2)
▪ is greater than
● (num1 > num2)
▪ is greater than or equal to
● (num1 >= num2)
▪ is less than
● (num1 < num2)
▪ is less than or equal to
● (num1 <= num2)

17
Q

JavaScript:
Inputting/Outputting Data

A

Inputting and Outputting Data
▪ var customerName = prompt(“Please enter your name”);
if (customerName!= null) {
document.getElementById(“welcome”).innerHTML =
“Hello “ + customerName + “, How are you today?”;
}

18
Q

Ruby:

Inputting/Outputting Data

A

puts “Please enter your name:”
userName = gets
puts “Hello ” + username
Please enter your name: Jason
Hello Jason