CISA3309_600 Scripting

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Using PowerShell string and date formatters, write a statement to print today's date in: Mar-06-2021 format. Note: You cannot hard code the date. It must use the System date

"{0:MMM}-{0:dd}-{0:yyyy}" -f (Get-Date) or get-date -format "MMM-dd-yyyy" or Get-Date -f "MMM-dd-yyyy" or Get-Date -UFormat %b-%d-%Y

Select wrong variable names in PowerShell

$_%variable = 10 $2%variable=50;

a. Define a string variable called $compoundWord and initialize it with "up to date". b. Change the $compoundWord to be "up-to-date" using a string operation function. c. Extend the $compoundWord using a string operation function so that at the end of the operation, the compoundWord will have the phrase "up-to-date user guide."

$compoundWord ="up to date" $compoundWord = $compoundWord.replace(" ", "-"); $compoundWord = $compoundWord+ " user guide." $compoundWord

If you are interested in finding out the type of a variable named $myVariable then you should use

$myVariable.getType().Name

Write a Powershell Script to: 1. Read two numbers into double variables 2. Print the following information and relationships on screen 3. Write the same information displayed in 2. to a file named myReport.txt 4. Script must contain code to delete the previous file myReport.txt, if the user runs the report again, and re-create the file myReport.txt for the current run. *After executing your script, on command line run the Get-Content cmdlet on myReport.txt and show the contents of the file Here is an example output:

$num1 = read-host -Prompt "Enter Ist number" $num2 = Read-Host -Prompt "Enter Second number" [int]$Num1 = [convert]::ToInt32($num1, 10) [int]$Num2 = [convert]::ToInt32($num2, 10) $sum = $num1 + $num2 Write-Host "Result: $sum"

Names=('John' 'Jacob' 'Joseph' 'Joe' 'Jay'); echo ${Names[@]:2:3} will print Joseph Joe Jay

False

PS C:\Users\compadmin> $myDef = "The", "Fox", "Jumped", "Over", "The", "Wall" In the above command, $myDef is a single valued variable.

False

The $ sign is used as a prefix to both assign and access the value of variables in bash

False

The -eq operator can be used to compare any data type in bash.

False

The statement: echo 'display=3;60.4+5.3/2' | bc will print the value 63.050

False

What can cat command do in addition to displaying the contents of a file?

Creating

It is possible to identify the type of a variable by using the getVariabletype() method of the object

False

A developer wants to match if the word or word part "log" exists in an input string. For example if a user enters "logic" or "Prolog" the program prints a statement like: String logic has the word "log". OR String prolog has the word "log". Assuming the input string is in the variable $inputStr, the correct bash statement to match and check for the pattern is: if [ $inputStr == *log* ] then echo "String has the word \"log.\" fi

False

Assume that you have a file named sentence.txt with the following text in it. I fly past the smaller shops, past the men drinking wine on the benches, past the old men playing dominoes, past the restaurants and the Arabs selling clothes and rugs and shoes, past the twins my age, Ahok and Awach Ugieth, two very kind and hardworking girls carrying bundles of kindling on their heads, Hello, Hello, we say, and finally I step into the darkness of my father's stores, completely out of breath. You run the following command: sed 's/past/over/' ./sentence.txt After executing the command, every 'past' is replaced by 'over' and the file now contains: I fly over the smaller shops, past the men drinking wine on the benches, past the old men playing dominoes, past the restaurants and the Arabs selling clothes and rugs and shoes, past the twins my age, Ahok and Awach Ugieth, two very kind and hardworking girls carrying bundles of kindling on their heads, Hello, Hello, we say, and finally I step into the darkness of my father's stores, completely out of breath.

False

Assume that you have a file named testfile.txt in the current directory. On the command line, to quick display of contents of the file testfile.txt, we can use all of the following: list ./testfile.txt cat ./testfile.txt more ./testfile.txt

False

If a string is given like this: aString=ABCDEFGHIJKLMNOPQRST and then you execute the following command echo ${aString: -8} will print the result: MNOPRST

False

In a statement like this.... unset myArray[5] the location subscribed by 5 will be set to value 0.

False

You are given a file named mywords.txt to be sorted. You run the following command: sort < mywords.txt now the original file mywords.txt is sorted.

False

for i in {0..10..3} do echo "The next number is $i" done The above block of code will print 10 lines one under the other stating from The next number is 0 and ending with The next number is 27

False

printf "%f\n" "1.32" "3.14" The above statement will print 1.32 3.14

False

Select all commands that produce today's date in long format.

Get-Date date get-date

A User executed a Powershell command and the output was Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ----------- ---------- -------- --------- --------- -- -- ------------------ 737 31 61956 78496 2.58 7132 7 powershell 916 66 152952 181056 66.38 7792 7 powershell_ise Write the command this user typed.

Get-Process | Where-Object {$_.ProcessName -Match "^p.*"} or Get-Process | Where-Object {$_.ProcessName -match "^powershell*"}

Write a complete bash script to print a receipt for a wholesale business. Assume that the business is selling only Three items always and their prices are fixed. The items business sells are : Shirts/$29.45 each, Pants/$12.89 each and Pairs of Socks/$3.56 each.There are two categories of byers, Taxable and Tax Free buyers. If the buyer is a tax free buyer, no tax is chargedbut an indications is printed in the receipt (See receipt examples below). Here are the criteria you must have to get full credit: - Per Unit value and Cost must print 2 decimal places. - Number of units purchased must print 1 decimal place.- All number values MUST right-aligned. - $signs must be printed as shown- 6.25% Tax is charged only on Taxable buyers - Print **This sale for a tax Free Business at the bottom of the receipt if the buyers is a Tax Free buyer.- Print a greeting to thank the customer and the date at the end of the receipt.- Neatness is Important. Match the given example outputs exactly. Here is an example receipt each (Tax Free buyer and Taxable buyer respectively).

Selected Answer: #!/bin/bash#File Name : business_performance.dat..little to no instruction 90% googlefu. #Using formatters to print a table with an input file file="./business_performance.dat" read -p "Enter Account Institution Name: <Global Wholesale Inc.>" COLUMNS=$(tput cols) #columns 3wd=$(($COLUMNS/4)) # items for saleShirts=29.45Pants=12.89Socks=3.56 printf "\n%-*s%*s%*s%*s%*s%*s\n" $wd "Item Name" $wd "Per Unit($)" $wd "Units" $wd "Cost" # print an empty line on the terminalprintf "\n" printf "%*s" $COLUMNS '' | tr ' ' . printf "\n" while IFS=, read -r data1 data2 data3 data4 data5; dointer2f=$(echo "$data2*$data3/100" | bc -l) # Print Columnswd=$(($COLUMNS/3))printf "%-*s%*.2f%*.2f%*.2f%*.2f%*.2f\n" $wd "$data1" $wd "$data2" $wd "$data3" $wd "$data4" $total_cost# print a line of dashes followed by a new line# just like we printed an entire line of dotsprintf "%*s" $COLUMNS '' | tr ' ' -printf "\n"done < "$file" # print an empty line on the terminalprintf "%*s" $COLUMNS '' | tr ' ' -printf "\n" # do not have time to do the rest with would need to calculate totals and utilize the intial forcasted profit loss along with totals calulated to print out results. Correct Answer:[None]Response Feedback: There are no loops needed. use an if statement to determine tax free of not."*tax free business" should not be printing for all

What is "$1" sign in shell script?

The first argument to a shell script

If you are given a string like this: statement = "Town In Texas May Be The Wealthiest In The US" Write a bash statement to build the string "Wealthiest Town In The US" by using the given string. Note: Hard coding a string to match what is required will not get any points. You must use the given string named statement.

There are several ways you can do this. Most easy to understand answer is: s=" " w=${statement:24:11} t=${statement:0:5} i=${statement:36} echo $w$s$t$s$i

* and ? are both valid bash wildcards.

True

1. mv myfile1.txt myNewdir Moves the file "myfile1.txt" to the directory "myNewdir" 2. mv myfile1 subdir/myfile2 Moves the file "myfile1" to the sub-directory named "myfile2" 3. mv bak1 bak2 Renames the directory "bak1" to "bak2" Are all Correct?

True

A PowerShell programmer wrote three statements like this: $x = 1,3 $y = 5,9 $z = $x + $y He thought he could add two arrays like shown in the third line above. Is he right? (yes = true, no = false)

True

A set of folders in Ernest's home directory is listed below: drwxr-xr-x 2 ernest ernest 4096 Jul 20 2019 app-defaults/ drwxrwxr-x 4 ernest ernest 4096 May 25 2019 arabic/ drwxrwxr-x 2 ernest ernest 4096 Jan 4 18:30 bin/ drwxr-xr-x 7 ernest ernest 4096 Sep 2 2018 crossover/ drwxrwxr-x 3 ernest ernest 4096 Jan 22 2019 xml/ If the command: ls -ld [a-cx-z]* is executed, on the above folders, then the result will list all files in Ernest's home directory, starting with "a", "b", "c", "x", "y" or "z"

True

A string which can span multiple lines is a single-quoted or double-quoted string. These strings are called here strings; thus they must start and end with a '@' character.

True

Alias is a command that enables a replacement of a word by another string, used mainly for abbreviating a system command.

True

An alternative and usually shorter name for a command is referred to as an alias

True

If I want to read three values from the bash command line into three different variables, can I do something like this? read variabl1, variable2, variabl3 yes you can = true, no you cannot = false

True

In order to get a list of all cmdlets available, we can use the PowerShell command Get-Command

True

PowerShell has two built-in variables $true and $false for displaying the true and false boolean values

True

The $_ symbol in PowerShell is also called the 'Pipe Line'.

True

The command $* shall read the string that contains all the arguments sent into a script on the command line.

True

The following script: for i in 1 2 3 do echo "Welcome $i times" done when executes, it will print Welcome 1 times Welcome 2 times Welcome 3 times

True

Given the folliwing code snippet: echo -n "Enter a number: " read aVariableif ( $aVariable -gt 10 ) then echo "The variable is greater than 10." fiThere is an error in the if statement.Which one of the following will fix the problem and execute the echo statement?

[[ $aVariable -gt 10 ]]

To assign a boolean value to a variable, a student tried several ways. Select the ones that is not right.

[bool]$boolVal=True

Write a Powershell statement to print today's day of the year For example, in the year 2021, March 06 is the 65th day.

get-date -DisplayHint Date .dayofyear | (Get-Date -Year 2021 -Month 3 -Day 14).DayOfYear

Write in two steps.... -Initialize a counter variable to 8 -increment the counter variable by 1

counter=8 counter =$(( $ counter + 1 )) or counter=8 ((counter++))

Select the correct array definition in bash

disney=("Welcome" "To" "Disney" "Disney")

In a folder the user executed a command on two files named output.txt and patterns.sh and the following outputs were created by the system: User executed a command on output.txt. result: output.txt: ASCII text User executed the command on patterns.sh. result: patterns.sh: Bourne-Again shell script, ASCII text executable What is the command user may have executed? Just write the command (expected one word answer).

file

Given the array myArray=(one two three four five) Select snippets which will reveal any information of contents of each cell.

for index in ${!myArray[*]} do printf " %d\n" $index done for index in ${!myArray[*]} do printf "%4d: %s\n" $index ${myArray[$index]} done

Given the following block of code: file="./values.dat" while IFS=, read -r value1 value2 value3; do printf "%-10s %6.2f %6.2f %6.2f\n" "$value1" "$value2" "$value3" done <"$file" Write in your own words what this block of code is doing.

it is looking in a "read-only variable" then printing out the information for value1, value2 and value3

Write a statement in bash to list the latest 10 files in a directory. (Expected only 1 line in the answer)

ls -lt | head ls -lt | head -10 ls -ltur | head -10

The Bash command that allows us to see our current directory

pwd

In bash, a Stream Editor command is

sed

In the command: C:\users> ("aBCdefBCghi").XXXXX("BC") when executed after substituting a function at XXXXX, the result was: a def ghi What the function user substituted at XXXXX?

split


Set pelajaran terkait

Chapter 8 : Caring For Patients With Chronic Illness EAQ

View Set

ATI The Gastrointestinal System Test 4.0

View Set

Sadlier Vocabulary Workshop - Level B - Unit 1 - Completing the Sentence

View Set