Scripting Languages Comparison Flashcards
How do you assign variables in PowerShell?
Only language where its different
$varName=value
How do you display a variable to terminal in Bash?
echo $varName
How do you display a variable to terminal in PowerShell?
Write-Host $varName
How do you display a variable to terminal in Ruby?
puts varName
What are the comparison operators in Bash?
-eq (==), -ne (!=), -lt (), -ge (>=)
What are the comparison operators in PowerShell?
-eq, -ne, -gt, -ge, -lt, -le
What are the comparison operators in Ruby?
==, !=, >, >=,
What are the comparison operators in Python?
==, != (<>), >, >=,
What are the different kinds of loops in Bash?
For
What are the different kinds of loops in PowerShell?
For, While, Do-While, Do-Until
What are the different kinds of loops in Ruby?
while, until, for
What are the different kinds of loops in Python?
for, while
Flow Control in Bash
if condition then commands elif commands else commands fi
Flow Control in PowerShell
if (condition) { statements } elseif (condition) { statements } else { statements }
Flow Control in Ruby
if condition then statements elsif statements else statements end
Flow Control in Python
if condition: statements elif condition: statements else: statement
How to input from the terminal in Bash?
Read –p “Prompt:” var
How to input from the terminal in PowerShell?
$firstName = Read-Host –Prompt ‘Enter first name’
How to input from the terminal in Ruby?
name = gets
How to input from the terminal in Python?
Name = raw_input(‘Please enter your name’)
Error handling in Bash
If [“$?’ = “o”] then
Error handling in PowerShell
try { Command } catch { errHandling commands }
Error handling in Ruby
begin statements rescue statements if error occurred else statement if no error end
Error handling in Python
try: statements raise except: statements customErrorObject finally: statements to clean up
Arrays in Bash
bashArray = (val1, val2, val3) For I in 1 2 3 Do echo ${bashArray[$i]}
Arrays in PowerShell
$PSarray=@(1.3.5.7.9); for($i = o; $1 –lt $PSarray.Length; $i++) { $PSarray[$1] } Foreach ($element in $PSarray) { $element }
Arrays in Ruby
rubyArray = [“val1”, “val2”, “val3”]
print rubyArray[1]
print
Arrays in Python
pythonArray = [10,20,30,40,50]
print(pythonArray[1])
len(pythonArray)