PROG1901 TEST 1 PRACTICE QUIZ
30 Questions
8 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

How can you display the value of a variable in PowerShell?

  • Use the Write-Output cmdlet
  • Enclose the variable name in quotes
  • Use the Write-Host cmdlet with the variable name within double quotes (correct)
  • Assign the variable to a new variable for display
  • In PowerShell, how is selection logic formatted similar to C#?

  • if condition: then true statements else false statements
  • if (condition) then true statements else false statements
  • if (condition) { true statements } elseif { other statements } else { false statements }
  • if (condition) { true statements } else { false statements } (correct)
  • Which operator is used before a comparison in PowerShell?

  • -and
  • -eq
  • -gt
  • -not (correct)
  • How should user-defined functions be placed in a PowerShell script?

    <p>Before any other code as they must be declared before being called</p> Signup and view all the answers

    What array holds values passed to a function in PowerShell?

    <p>$args</p> Signup and view all the answers

    Which logical operator in PowerShell means 'only one can be true'?

    <p>-xor</p> Signup and view all the answers

    What is the correct comparison operator for 'greater than' in PowerShell?

    <p>-gt</p> Signup and view all the answers

    To output text along with a variable value to the screen in PowerShell, which cmdlet should be used?

    <p>Write-Host</p> Signup and view all the answers

    In PowerShell, what should a condition evaluate to in selection logic?

    <p>$true or $false values indirectly</p> Signup and view all the answers

    What keyword is used to create a function in PowerShell?

    <p>function</p> Signup and view all the answers

    How can you store the output of a command in a variable in Bash by using command substitution?

    <p>Placing the command in round brackets preceded by the $ sign</p> Signup and view all the answers

    What happens when the output of a command in Bash is more than one line and stored in a variable?

    <p>The entire output is converted to a single line and stored in the variable</p> Signup and view all the answers

    How can you make a variable available in other bash shells in Bash scripting?

    <p>Use the export keyword before the variable name</p> Signup and view all the answers

    What is the scope of variables declared in a script in Bash by default?

    <p>Local to the script only</p> Signup and view all the answers

    In Bash scripting, what effect does 'export' have when used with a variable?

    <p>It makes a copy of the variable available in other shell instances</p> Signup and view all the answers

    Which symbol is used for command substitution in Bash scripting?

    <p>$(</p> Signup and view all the answers

    What happens if you declare a variable without using 'export' in a Bash script?

    <p>The variable is only accessible within that script instance</p> Signup and view all the answers

    How does exporting a variable affect its modifications in Bash?

    <p>'export' reflects changes globally across all instances of the shell</p> Signup and view all the answers

    What does exporting a variable allow you to do in Bash?

    <p>Access the variable across multiple scripts and shell instances</p> Signup and view all the answers

    In Bash scripting, what does 'o myVar=$( ls /etc ) o' demonstrate?

    <p>Command substitution to assign output to a variable</p> Signup and view all the answers

    What is the main focus of information security according to the text?

    <p>Protecting information stored, manipulated, and transmitted</p> Signup and view all the answers

    Which aspect of information security ensures that only approved individuals can access important data?

    <p>Confidentiality</p> Signup and view all the answers

    What does authentication aim to achieve in information security?

    <p>Verifying the identity of users</p> Signup and view all the answers

    In what way do attacks on information security demonstrate increased sophistication?

    <p>Attack tools vary their behavior to evade detection</p> Signup and view all the answers

    Which element ensures that the individual is who they claim to be in information security?

    <p>Authentication</p> Signup and view all the answers

    What is a threat vector?

    <p>The means by which an attack can occur</p> Signup and view all the answers

    Why do organizations find it challenging to provide security for personal devices under BYOD?

    <p>Organizations face difficulty in securing a wide array of personal devices</p> Signup and view all the answers

    What is a vulnerability in the context of information security?

    <p>A flaw or weakness that allows a threat agent to bypass security</p> Signup and view all the answers

    How are attacks different due to the availability and simplicity of attack tools?

    <p>No longer limited to highly skilled attackers</p> Signup and view all the answers

    What defines a threat agent in the context of information security?

    <p>A person(s) or element capable of carrying out a threat</p> Signup and view all the answers

    Study Notes

    Windows Scripting Overview

    • Windows supports various scripting languages, including Batch, PowerShell, VBScript, and JScript, which use text files for source code and automate tasks at the operating system level.
    • These languages offer basics such as creating and using variables, input from the user and output to the user, use of control structures like if, switch, for, and while, and support for functions and arrays.

    Batch File Scripting

    • Batch files have a .bat or .cmd extension, with .cmd being the preferred extension.
    • Functions in batch files:
      • Are defined with a label and a colon
      • The body of the function contains any logic and commands
      • The last line of a function is usually exit /B 0, which exits the script with an error code of zero
      • Functions don't return to the line of code they are called from
      • To call a function, use the call keyword followed by the label name and any values to be passed
    • Example batch file script:
      • Creates folders and files in the Documents directory
      • Uses verbs like Get, Set, Start, Stop, Out, and New to perform actions

    PowerShell

    • PowerShell is a powerful scripting language based on .NET
    • To get help, use the get-help command (cmdlet)
    • Examples of get-help usage:
      • get-help for an overview of the help system
      • get-help dir to get help on the dir command
      • get-help about* to get a list of conceptual help files
      • get-help clear* to list cmdlets starting with the word clear

    Linux Scripting (BASH) Overview

    • BASH (Bourne Again shell) is the default shell for most Linux distributions
    • Other shells include Korn Shell (ksh), C Shell (csh), and variations like tcsh

    BASH Scripting Basics

    • Shell scripts are text files that end in .sh (but it's not required)
    • The first line of the script must indicate the shell that should be used to execute the script (#!/bin/bash)
    • Comments start with #
    • To execute a script, change the file permissions for the user, group, and other categories using chmod ugo+x or chmod 755
    • Example of changing file permissions:
      • chmod ugo+x adds execute rights to the user, group, and all other users
      • chmod 755 sets the file permissions to rwx r-x r-x

    Variables in BASH

    • Variables are not declared, and values are assigned using the assignment operator (=)
    • Variables are assigned as strings but can be converted to numbers when necessary
    • Access the value of a variable using the $ sign
    • Output the value of a variable using echo
    • Input a value using read
    • Bash scripts have access to command line arguments (positional variables) and environment variables.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    01Lecture-WindowsScripting.pdf
    02Lecture-LinuxScripting.pdf
    03Lecture-NetworkSecurity1.pdf

    Description

    Test your knowledge of PowerShell commands with this quiz! Identify the corresponding actions to common verbs used in PowerShell commands and understand their functionalities. Learn about using the get-help command to navigate and utilize the help system effectively.

    Use Quizgecko on...
    Browser
    Browser