Bash LinkedIn Skill Assessment Answer

Rate this post

Here, We see Bash LinkedIn Skill Assessment Answers. This assessment test consists 15-20 MCQs to demonstrate your knowledge in your selected skills. MCQs comes from different topics – Bash Operators, Scripting, Expansion, Environment, Constructs.

Table of Contents

Q1. Which of the three methods will copy the directory named “photo dir” recursively from the user’s home directory to /backups?

cp -R "~/photo dir" /backups #method1
cp -R ~"/photo dir" /backups #method2
cp -R ~/"photo dir" /backups #method3
  1. None of the three methods will expand to the user’s home directory. Only using "$HOME/photo dir"will be successful.
  2. Only method 1 will expand "~/" to the user’s home directory and then append the quoted directory name that includes a space.
  3. Only method 2 will expand "~/" to the user’s home directory and then append the quoted directory name that includes a space.
  4. Only method 3 will expand "~/" to the user’s home directory and then append the quoted directory name that includes a space.✔️

Q2. If script.sh is run in the current directory, it will fail. Why?

$ ls -1
Beach photo*jpg
Photo*jpg
Photo2.jpg
Script.sh

$ cat script.sh
for i in $(ls *.jpg); do
	mv $i ${i}.bak
done
  1. ls: cannot access nonexistentfile: No such file or directory
  2. The for loop will split on word boundaries and Beach photo*jpg has a space in it.✔️
  3. The mv command will fail because the curly bracket is a special character in Bash and cannot be used in the names of files.
  4. Running script.sh will be successful as the ls command builds a list of files in the current directory and for loops through that list renaming files with a .bak extension.

Q3. To run a copy command in a subshell, which syntax would you use?

  1. ( command )✔️
  2. sh command
  3. { command; }
  4. (( command ))

Q4. Using “awk”, what would the output of this command string be?

echo "1 2 3" | awk '{for (i=1; i<=NF; i++) s=s+$i};END {print s}'
  1. 6✔️
  2. 123
  3. 3
  4. 600

Q5. The command below will search the root filesystem for files named “finance.db”. In this context, what information is being sent to /dev/null?

find / -name "finance.db" 1>results.txt 2>/dev/null
  1. the names of files that do not match finance.db
  2. information sent to the standard error-for example, errors that the find command displays as it runs✔️
  3. the names of files that match finance.db
  4. information sent to the standard output-that is, the path to files the find command has located

Q6. To permanently remove empty lines from a file called textfile, which command could you use?

  1. sed -i '/^$/d' textfile✔️
  2. sed '/^$/d' textfile
  3. cat textfile | sed '/^$/d
  4. sed -i 's/^$//' textfile

Q7. Assuming that user1 existed, what would be the result of this command string?

awk -F: '/user1/{print $1 "-" $3 "-" $6}' /etc/passwd
  1. It would show the username, UID, and home directory of user1 separated by colons.
  2. It would print the UID, GID, and home directory of user1 separated by hyphens.
  3. It would print the UID, comment, and home directory of user1 separated by hyphens.
  4. It would show the username, UID, and home directory of user1 separated by hyphens.✔️

Q8. What happens if you use the "set -e" in a Bash script?

  1. It will cause Bash to exit if a function or subshell returns a nonzero status code.
  2. It will cause Bash to exit if a conditional returns a non-zero status code.
  3. It will cause Bash to exit if local, declare, or typeset assignments return a nonzero status code.
  4. It will cause Bash to exit if a command, list of commands, compound command, or potentially a pipeline returns a nonzero status code.✔️

Q9. The _ keyword pauses the script to get input from standard input.

  1. get
  2. argument
  3. read✔️
  4. input

Q10. If file.sql holds SQL statements to be executed, what will be in file.txt?

mysql < file.sql > file.txt
  1. a copy of the contents of file.sql
  2. an error indicating that this is invalid syntax
  3. the error output of the MySQL command
  4. the non-error output of the MySQL command✔️

Q11. How does the SUID or setuid affect executable commands?

  1. When the command creates files, they will be owned by the group owner of the command.
  2. The SUID bit allows anyone to execute the command no matter what other permissions are set.
  3. When the command is executed, its running privileges elevate to the user owner of the command.✔️
  4. When the command is executed, its running privileges elevate to the group owner of the command.

Q12. In order to extract text from the first column of file called textfile, which command would you use?

  1. cat {$1,textfile}
  2. cat textfile | awk [print $1]
  3. cat textfile | awk '{print $1}'✔️
  4. awk textfile {print $1}

Q13. What is the keyboard shortcut to call up the Bash history search as shown below?

(reverse-i-search)`':
  1. Esc + R
  2. Ctrl + H
  3. Ctrl + R✔️
  4. Alt + R

Q14. Which arithmetic expression will give the most precise answer?

  1. var=$( expr 10 / 8 )
  2. (( var= 10 /8 ))
  3. var=$(( 10 / 8 ))
  4. var=$(echo 'scale=2; 10 / 8' | bc)✔️

Q15. What is the result of this script?

txt=Penguins
[[ $txt =~ [a-z]{8} ]]; echo $?
  1. 0, representing ‘true’, because the variable “txt” contains eight letters
  2. 0, representing ‘true’, because everybody loves penguins!
  3. 1, representing ‘false’, because the variable “txt” is longer than eight characters
  4. 1, representing ‘false’, because the variable “txt” does not contain eight lowercase letters between a and z✔️

Q16. How would you change your Bash shell prompt to the following?

HAL>
  1. SHELL="HAL\>"
  2. SHELL="HAL>"
  3. export PS1="HAL>"✔️
  4. PS1="HAL\>"

Q17. What is the output of this code?

VAR="/var/www/html/website.com/html/"
echo "${VAR#*/html}"
  1. /website.com/html/✔️
  2. /html/website.com/html/
  3. /var/www/html/website.com/
  4. Nothing will be echoed on the screen.

Q18. If prompted for text at the standard input, you can tell the command you’re done entering text with what key combination?

  1. Ctrl + A (Windows) or Command + A (Mac)
  2. Ctrl + E (Windows) or Command + E (Mac)
  3. Ctrl + D (Windows) or Command + D (Mac)✔️
  4. Ctrl + Z (Windows) or Command + Z (Mac)

Q19. In order for a Bash script to be executed like an OS command, it should start with a shebang line. What does this look like?

  1. #!/usr/bin/env bash✔️
  2. ~/usr/bin/env bash
  3. '$!/usr/bin/env bash
  4. #/usr/bin/env bash

Q20. What line of Bash script probably produced the output shown below?

The date is: Sun Mar 24 12:30:06 CST 2019!
  1. echo "The date is: !"
  2. echo "The date is: date!"
  3. echo "The date is: (date)!"
  4. echo "The date is: $(date)!"✔️

Q21. Suppose your current working directory is your home directory. How could you run the script demo.sh that is located in your home directory? Find three correct answers.

A. /home/demo.sh
B. ./demo.sh
C. ~/demo.sh
D. bash /home/demo.sh
E. bash demo.sh
  1. B, C, E✔️
  2. A, B, C
  3. C, D, E
  4. B, D, E

Q22. How could you get a list of all .html files in your tree?

  1. find . -type html
  2. find . -name *.html
  3. find *.html
  4. find . -name \*.html -print✔️

The second seems well, but will expand the * if there is any .html file on your working directory.

Q23. What would be in out.txt?

cat < in.txt > out.txt
  1. The output from the command line. By default STDIN comes from the keyboard.
  2. Nothing because you can’t redirect from file (in.txt) to another file (out.txt). You can only redirect from a command to a file.
  3. It would be the contents of in.txt.✔️
  4. Nothing. The redirect will create a new empty file but there will not be any output from the cat command to redirect.

Q24. What does this bash statement do?

(( $a == $b ))
echo $?
  1. It loops between the values of $a and $b.
  2. It tests whether the values of variables $a and $b are equal.✔️
  3. It returns $b if it is larger than $a.
  4. It returns $a if it is larger than $b.

Q25. What do you use in a case statement to tell Bash that you’re done with a specific test?

  1. ; ;✔️
  2. : :
  3. done
  4. $$

Q26. What does the asterisk represent in this statement?

<em>#!/usr/bin/env bash</em>
case $num in
	1)
	echo "one"
	; ;
	2)
	echo "two"
	; ;
	*)
	echo "a mystery"
	; ;
esac
  1. a case that matches any value, providing a default option if nothing else catches that value✔️
  2. a case only for what happens when the asterisk character is passed into the script
  3. the action of all of the other cases combined together
  4. an action that is taken for any input, even if it matches a specified condition

Q27. What Bash script will correctly create these files?

  1. touch file{1+10}.txt
  2. touch file{1-10}.txt
  3. touch file{*.10}.txt✔️
  4. touch file(*.10).txt

Q28. Which variable would you check to verify that the last command executed successfully?

  1. $$
  2. $?✔️
  3. $!
  4. $@

Q29. What is the output of this script?

#!/bin/bash
fname=john
john=thomas
echo ${!fname}
  1. john
  2. thomas✔️
  3. Syntax error
  4. blank

Q30. What will be the output of this script?

Here a text based version of Q.30:

ll
-rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
-rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file*txt
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.txt
..

ll | sed -e 's,file,text,g'

  1. A
  -rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
  -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
  -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file*file
  -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.file
  ..
  1. B
  -rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
  -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
  -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file*txt
  -rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 file2.txt
  ..
  1. C
  -rw-r--r-- 1 frankmolev staff 68 Jun 3 19:30 .
  -rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
  1. D ✔️
-rw-r--r-- 1 frankmolev staff 374 Jun 3 19:30 .
-rw-r--r-- 1 frankmolev staff 1666 Jun 3 19:30 ..
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 text*txt
-rw-r--r-- 1 frankmolev staff 0 Jun 3 19:30 text.txt
..

Q31. What is wrong with this script?

#!/bin/bash
read -p "Enter your pet type." PET
if [ $PET = dog ] ;then
    echo "You have a dog"
fi
  1. If the value of PET doesn’t match dog, the script will return a nonzero status code.
  2. There is nothing wrong with it. The condition checks the value of PET perfectly.
  3. It will fail if the user hits the Enter (Return) key without entering a pet name when prompted.✔️
  4. The then statement needs to be on a separate line.

Q32. How can you gather history together for multiple terminals?

  1. It just works by default.
  2. history --shared
  3. history --combined
  4. shopt -s histappend✔️

Q33. What is the difference between the $@ and $* variables?

  1. $@ treats each quoted argument as a separate entity. $ treats the entire argument string as one entity.✔️*
  2. $* treats each quoted argument as a separate entity. $@ treats the entire argument string as one entity.
  3. $* is used to count the arguments passed to a script, $@ provides all arguments in one string.
  4. $* is the wildcard that includes all arguments with word splitting, $@ holds the same data but in an array.

Q34. Which command is being run in this script to check if file.txt exists?

if [ -f file.txt ]; then
    echo "file.txt exists"
fi
  1. /usr/bin/test
  2. /usr/bin/[
  3. the built-in [ command✔️
  4. /usr/bin/[[

Q35. What will be the output of this script?

#!/bin/bash
Linux=('Debian' 'Redhat' 'Ubuntu' 'Android' 'Fedora' 'Suse')
x=3

Linux=(${Linux[@]:0:$x} ${Linux[@]:$(($x + 1))})
echo "${Linux[@]}"
  1. Debian Redhat Ubuntu Android Fedora Suse
  2. Android
  3. Fedora Suse
  4. Debian Redhat Ubuntu Fedora Suse✔️

Q36. Which file allows you to save modifications to the shell environment across sessions?

  1. /etc/bash.conf
  2. ~/.profile✔️
  3. /etc/bashprofile
  4. ~/profile

Q37. Given the listed permissions on data.txt is it possible that user2 could have read, write, and execute permissions on data.txt?

$ ls -l
total 0
-rwx------+ 1 user1 user1 0 Oct 27 10:54 data.txt
  1. No, it’s clear that user2 does not have read, write, and execute permissions.
  2. Yes, the + at the end of the 10-digit permission string signifies there’s an access control list. This could possibly give user2 permissions not visible by ls -l.✔️
  3. It’s possible that SELinux provides read, write, and execute permissions for user2 which are not visible with ls -l.
  4. Yes, the + at the end of the 10-digit permission string signifies there’s an extended attribute set. This could give user2 permissions to read, write, and execute data.txt.

Q38. What does this script accomplish?

#!/bin/bash
declare -A ARRAY=([user1]=bob [user2]=ted [user3]=sally)
KEYS=(${!ARRAY[@]})

for (( i=0; $i < ${#ARRAY[@]}; i+=1 ));do
        echo ${KEYS[$i]} - ${ARRAY[${KEYS[$i]}]}
done
  1. It sorts the associative array named ARRAY and stores the results in an indexed array named KEYS. It then uses this sorted array to loop through the associative array ARRAY.
  2. Using a C-style for loop, it loops through the associative array named ARRAY using the associative array’s keys and outputs both the key and values for each item.✔️
  3. It creates an indexed array of the associative array named ARRAY. It then uses a C-style for loop and the indexed array to loop through all items in the associative array, outputting the key and value of each array item using the index number.
  4. It creates an associative array named ARRAY, which it loops through using a C-style for loop and the index numbers of each item in the associative array’s keys, outputting the value of each item.

Q39. What file would match the code below?

ls Hello[[.vertical-line.]]World
  1. Nothing, this is an invalid file glob.
  2. Hello.vertical-line.World
  3. Hello[[.vertical-line.]]World
  4. Hello|World✔️

Q40. What will be in out.txt?

ls nonexistentfile | grep "No such file" > out.txt
  1. No such file
  2. ls: cannot access nonexistentfile: No such file or directory
  3. Nothing, out.txt will be empty.✔️
  4. It will be the contents of nonexistentfile.

Q41. For the script to print “Is numeric” on screen, what would the user have to enter when prompted?

#!/bin/bash
read -p "Enter text " var
if [[ "$var" =~ "^[0-9]+$" ]];then
    echo "Is numeric"
else
    echo "Is not numeric"
fi
  1. Any sequence of characters that includes an integer
  2. The user would have to enter the character sequence of ^[0-9]]+$ Only this will prove to be true and “Is numeric” would be printed on the screen due to incorrect syntax. By encapsulating the regular expression in double quotes every match will fail except the text string ^[0-9]+$
  3. One or more characters that only includes integers
  4. Due to a syntax error it is impossible to get the script to print “Is numeric”✔️

The regex must not be quoted to work properly.

Q42. What will be the difference between the output on the screen and the contents of out.txt

mysql < file.sql > out.txt
  1. The output on the screen will be identical to out.txt
  2. There will be no output on the screen as it’s being redirected to out.txt.✔️
  3. The output on the screen will be identical to out.txt plus line numbers.
  4. The out.txt file will hold STDERR and STDOUT will go to the screen.

Q43. How would you find the last copy command run in your history?

  1. history | find cp
  2. history | grep cp✔️
  3. grep cp history
  4. cp history

Q44. In order to write a script that iterates through the files in a directory, which of the following could you use?

  1. bash for i in $(ls); do ... done✔️
  2. bash for $(ls); do ... done
  3. bash for i in $ls; do ... done
  4. bash for $ls; do ... done

Q45 When executing a command and passing the output of that command to another command, which character allows you to chain these commands together?

  1. |✔️
  2. ->
  3. #
  4. @

Q46. In the script shown below, what is greeting?

<em>#!/usr/bin/env bash</em>
greeting="Hello"
echo $greeting, everybody!
  1. a command
  2. a loop
  3. a parameter
  4. a vairable✔️

Q47. Which statement checks whether the variable num is greater than five?

  1. (( $num -gt 5 ))
  2. [[$num -lt 5]]
  3. (( $num > 5 ))✔️
  4. $num > 5

Q48. Using Bash extended globbing, what will be the output of this command?

$ ls -l
apple
banana
bananapple
banapple
pineapple
strawberry
$ shopt -s extglob
$ ls -l @(ba*(na)|a+(p)le)
  1. a✔️
apple
banana
  1. b
apple
banana
bananapple
banapple
pineapple
strawberry
  1. c
apple
banana
bananappple
banapple
pineapple
  1. d
apple
banana
bananapple
banapple
pineapple

Q49. When used from within a script, which variable contains the name of the script?

  1. $0✔️
  2. $# // number of positional parameters
  3. $$ // pid of the current shell
  4. $@ // array-like construct of all positional parameters

Q50. What does the + signify at the end of the 10-digit file permissions on data.txt?

ls -l
-rwx------+ 1 user1 u1 0 Oct 1 10:00 data.txt
  1. There is an SELinux security context
  2. The sticky bit is set and the file will stay in RAM for speed
  3. There is an access control list✔️
  4. There is an extended attribute such as immutable set

Q51. In Bash, what does the comment below do?

cd -
  1. It moves you to the directory you were previously in.✔️
  2. It moves you to your home folder (whatever your current working directory happens to be).
  3. It deletes the current directory
  4. It moves you one directory above your current working directory.

Q52. What does this command do?

cat > notes -
  1. Accepts text from standard input and places it in “notes”✔️
  2. Creates “notes” and exits
  3. Outputs the content of notes and deletes it
  4. Appends text to the existing “notes”

Q53. What is the output of:

VAR="This old man came rolling"
echo "\${VAR//man/rolling}"
  1. This old rolling came rolling✔️
  2. This old man came man
  3. This old man came rolling
  4. This old came

Q54. The shell looks at the contents of a particular variable to identify which programs it can run. What is the name of this variable?

  1. $INCLUDE
  2. $PATH✔️
  3. $PROGRAM
  4. $PATHS

Q55. What does this command sequence do?

cat >notes -
  1. It creates an empty file called “notes” and then exits.
  2. It accepts text from the standard input and places it in the “notes” file.✔️
  3. It appends text to an existing file called “notes.”
  4. It outputs the contents of the “notes” file to the screen, and then deletes it.

Q56. What is the output of this code?

VAR="This old man came rolling"
echo "${VAR//man/rolling}"
  1. This old man came man
  2. This old man came rolling
  3. This old rolling came rolling✔️
  4. This old came

Q57. What statement would you use to print this in the console?

  1. echo "Shall we play a game? yes/\no"
  2. echo "Shall we play a game\? yes\\no"
  3. echo "Shall we play a game? yes\\no"✔️
  4. echo "Shall we play a game? yes\no"

Leave a Comment

five × one =

CRICKET LIVE STREAMING