Iscriviti ora

Accesso

Password dimenticata

Hai perso la tua password? Inserisci il tuo indirizzo email. Riceverai un link e verrà creata una nuova password via e-mail.

Add postale

Devi effettuare il login per aggiungere post .

Aggiungere domanda

Devi effettuare il login per fare una domanda.

Accesso

Iscriviti ora

Benvenuti a Scholarsark.com! La tua registrazione ti darà accesso a utilizzare più funzionalità di questa piattaforma. È possibile porre domande, contributi o fornire risposte, Guarda i profili di altri utenti e molto altro ancora. Iscriviti ora!

LinkedIn skill assessment answers and questions – Bash

Bash is a popular scripting language that can help you automate tasks and perform various operations on Linux systems. If you want to showcase your Bash skills and knowledge, potresti voler prendere il LinkedIn skill assessment for Bash. This is a test that evaluates your proficiency in Bash and gives you a badge that you can display on your profile. tuttavia, passing the test is not easy, and you might need some help to prepare for it.

That’s why I have compiled a list of LinkedIn skill assessment answers and questions for Bash that you can use to study and practice. In questo articolo del blog, I will share with you some of the most common and tricky questions that you might encounter on the test, insieme alle risposte e alle spiegazioni corrette. Leggendo questo post, you will learn how to use Bash commands, variabili, loop, funzioni, e altro ancora. You will also get some tips and tricks on how to ace the test and impress potential employers with your Bash skills.

Q1. Which of the three methods will copy the directory namedphoto dirrecursively 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
  • None of the three methods will expand to the user’s home directory. Only using "$HOME/photo dir"will be successful.
  • Only method 1 will expand "~/" to the user’s home directory and then append the quoted directory name that includes a space.
  • Only method 2 will expand "~/" to the user’s home directory and then append the quoted directory name that includes a space.
  • 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. Come mai?

$ ls -1
Beach photo1.jpg
Photo1.jpg
Photo2.jpg
Script.sh

$ cat script.sh
for i in $(ls *.jpg); do
	mv $i ${i}.bak
done
  • ls: cannot access nonexistentfile: No such file or directory
  • The for loop will split on word boundaries and Beach photo1.jpg has a space in it.
  • The mv command will fail because the curly bracket is a special character in Bash and cannot be used in the names of files.
  • 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?

  • ( command )
  • sh command
  • { command; }
  • (( command ))

riferimento. Subshells are one way for a programmer to capture (usually with the intent of processing) the output from a program or script. Commands to be run inside a subshell are enclosed inside single parentheses and preceeded by a dollar sign: DIRCONTENTS=$(ls -l) echo ${DIRCONTENTS}

Q4. Usando “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}'
  • 6
  • 123
  • 3
  • 600

riferimento. AWK is a programming language that is designed for processing text-based data, either in files or data streams, or using shell pipes. In other words you can combine awk with shell scripts or directly use at a shell prompt.

Q5. The command below will search the root filesystem for files namedfinance.db”. In questo contesto, what information is being sent to /dev/null?

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

riferimento. Syntax to redirect stderr (standard error) to a file: command 2> errors.txt.

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

  • sed -i '/^$/d' textfile
  • sed '/^$/d' textfile
  • cat textfile | sed '/^$/d
  • sed -i 's/^$//' textfile

riferimento
sed : sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream.
-io[SUFFIX] : This option specifies that files are to be edited in-place.
‘/^$/d’ : regex is between the //. ^ is the beginning of the line, $ is the end of the line. ^$ means the start and end have nothing in between.
d : Delete the pattern space; immediately start next cycle.
avvertimento, this example above will not work on a mac terminal due to different UNIX flavours. There is a way to make it work on a mac adding an extra flag -e, or even just -- (found on StackOverflow): sed -i -e '/^$/d' textfile.txt

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

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

riferimento. tradizionalmente, the /etc/passwd file is used to keep track of every registered user that has access to a system. The /etc/passwd file is a colon-separated file that contains the following information: 1-Username, 2-Password, 3-User ID (UID), 4-Group ID (GID), 5-User ID Info (GECOS), 6-Home directory, 7-Command/shell

Q8. Cosa succede se usi il "set -e" in a Bash script?

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

riferimento. The set -e option instructs bash to immediately exit if any command [1] has a non-zero exit status. You wouldn’t want to set this for your command-line shell, but in a script it’s massively helpful. In all widely used general-purpose programming languages, an unhandled runtime errorwhether that’s a thrown exception in Java, or a segmentation fault in C, or a syntax error in Pythonimmediately halts execution of the program; subsequent lines are not executed.

D9. Il _ keyword pauses the script to get input from standard input.

  • ottenere
  • discussione
  • leggere
  • input

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

mysql < file.sql > file.txt
  • a copy of the contents of file.sql
  • an error indicating that this is invalid syntax
  • the error output of the MySQL command
  • the non-error output of the MySQL command

Nota: check the question below for a variant.

Dovrai almeno raggiungere. What will be the difference between the output on the screen and the contents of out.txt

mysql < file.sql > out.txt
  • The output on the screen will be identical to out.txt
  • There will be no output on the screen as it’s being redirected to out.txt.
  • The output on the screen will be identical to out.txt plus line numbers.
  • Il file out.txt conterrà STDERR e STDOUT verrà visualizzato sullo schermo.

Nota: check the question above for a variant.

D12. In che modo il SUID o il setuid influiscono sui comandi eseguibili?

  • Quando il comando crea file, saranno di proprietà del proprietario del gruppo del comando.
  • Il bit SUID consente a chiunque di eseguire il comando indipendentemente dalle altre autorizzazioni impostate.
  • Quando il comando viene eseguito, i suoi privilegi di esecuzione vengono elevati all'utente proprietario del comando.
  • Quando il comando viene eseguito, i suoi privilegi di esecuzione vengono elevati al proprietario del gruppo del comando.

riferimento. I diritti di accesso Linux e Unix contrassegnano setuid e setgid (abbreviazione di Imposta identità utente e Imposta identità di gruppo)[1] consentire agli utenti di eseguire un eseguibile con i permessi del file system rispettivamente del proprietario o del gruppo dell'eseguibile e di modificare il comportamento nelle directory.

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

  • cat {$1,textfile}
  • cat textfile | awk [print $1]
  • cat textfile | awk '{print $1}'
  • awk textfile {print $1}

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

(reverse-i-search)`':
  • Esc + R
  • Ctrl + H
  • Ctrl + R
  • Proteggerà le tue mani dalla superficie dura dei tasti e ti faciliterà la digitazione sul tuo computer o laptop senza alcun dolore alle dita o ai polsi + R

Nota: On the Mac it will show bck-i-search: invece di (reverse-i-search).

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

  • var=$( expr 10 / 8 )
  • (( var= 10 /8 ))
  • var=$(( 10 / 8 ))
  • var=$(echo 'scale=2; 10 / 8' | bc)

riferimento. The bc command is used for command line calculator. It is similar to basic calculator by using which we can do basic mathematical calculations. The division with 2 digit precision will be passed to bc, evaluated, and assigned to the variable.

Q16. What is the result of this script?

txt=Penguins
[[ $txt =~ [a-z]{8} ]]; echo $?
  • 0, representing ‘true’, because the variabletxtcontains eight letters
  • 0, representing ‘true’, because everybody loves penguins!
  • 1, representing ‘false’, because the variabletxtis longer than eight characters
  • 1, representing ‘false’, because the variabletxtdoes not contain eight lowercase letters between a and z

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

HAL>
  • SHELL="HAL\>"
  • SHELL="HAL>"
  • export PS1="HAL>"
  • PS1="HAL\>"

D18. What is the output of this code?

VAR="/var/www/html/website.com/html/"
echo "${VAR#*/html}"
  • /website.com/html/
  • /html/website.com/html/
  • /var/www/html/website.com/
  • Nothing will be echoed on the screen.

riferimento What is happening here quoting the POSIX shell specification: ${parameter#[word]}. Remove Smallest Prefix Pattern. The word shall be expanded to produce a pattern. The parameter expansion shall then result in parameter, with the smallest portion of the prefix matched by the pattern deleted.
Per esempio ${VAR#?} expands to the value of $VAR with the first character deleted. E ${VAR#\*/html}expands to include all characters to and including the/htmltext which will be deleted from the variable producing the output of/website.com/html/

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

  • Ctrl + UN (finestre) or Command + UN (Mac)
  • Ctrl + E (finestre) or Command + E (Mac)
  • Ctrl + D (finestre) or Command + D (Mac)
  • Ctrl + INSIEME A (finestre) or Command + INSIEME A (Mac)

Q20. 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?

  • #!/usr/bin/env bash
  • ~/usr/bin/env bash
  • '$!/usr/bin/env bash
  • #/usr/bin/env bash

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

The date is: Sun Mar 24 12:30:06 CST 2019!
  • echo "The date is: !"
  • echo "The date is: date!"
  • echo "The date is: (date)!"
  • echo "The date is: $(date)!"

Q22. 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
  • B, C, E
  • UN, B, C
  • C, D, E
  • B, D, E

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

  • find . -type html
  • find . -name *.html
  • find *.html
  • find . -name \*.html -print

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

Q24. What would be in out.txt?

cat < in.txt > out.txt
  • The output from the command line. By default STDIN comes from the keyboard.
  • 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.
  • It would be the contents of in.txt.
  • La sezione seguente sarà dedicata alla creazione di immagini di riferimento. The redirect will create a new empty file but there will not be any output from the cat command to redirect.

Q25. What does this bash statement do?

(( $a == $b ))
echo $?
  • It loops between the values of $a e $b.
  • It tests whether the values of variables $a e $b are equal.
  • It returns $b if it is larger than $a.
  • It returns $a if it is larger than $b.

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

  • ; ;
  • : :
  • done
  • $$

D27. What does the asterisk represent in this statement?

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

D28. What Bash script will correctly create these files?

  • touch file{1+10}.txt
  • touch file{1-10}.txt
  • touch file{1..10}.txt
  • touch file(1..10).txt

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

  • $$
  • $?
  • $!
  • $@

Q30. What is the output of this script?

#!/bin/bash
fname=john
john=thomas
echo ${!fname}
  • john
  • thomas
  • Syntax error
  • blank

riferimento

Q31. What will be the output of this script?

domanda

  • A UN
  • B B
  • C C
  • D D

Here’s 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 file1.txt
-rw-r--r-- 1 frankmolev staff 0     Jun 3 19:30 file2.txt
..

ll | sed -e 's,file,text,g'
  • UN
  -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 file1.file
  -rw-r--r-- 1 frankmolev staff 0     Jun 3 19:30 file2.file
  ..
  • 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 file1.txt
  -rw-r--r-- 1 frankmolev staff 0     Jun 3 19:30 file2.txt
  ..
  • C
  -rw-r--r-- 1 frankmolev staff 68    Jun 3 19:30 .
  -rw-r--r-- 1 frankmolev staff 1666  Jun 3 19:30 ..
  • 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 text1.txt
-rw-r--r-- 1 frankmolev staff 0       Jun 3 19:30 text.txt
..

Q32. 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
  • If the value of PET doesn’t match dog, the script will return a nonzero status code.
  • There is nothing wrong with it. The condition checks the value of PET perfectly.
  • It will fail if the user hits the Enter (Return) key without entering a pet name when prompted.
  • The then statement needs to be on a separate line.

____ base. How can you gather history together for multiple terminals?

  • It just works by default.
  • history --shared
  • history --combined
  • shopt -s histappend

Q34. What is the difference between the @���* variables?

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

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

if [ -f file.txt ]; then
    echo "file.txt exists"
fi
  • /usr/bin/test
  • /usr/bin/[
  • the built-in [ command
  • /usr/bin/[[

Q36. 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[@]}"
  • Debian Redhat Ubuntu Android Fedora Suse
  • androide
  • Fedora Suse
  • Debian Redhat Ubuntu Fedora Suse

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

  • /etc/bash.conf
  • ~/.profile
  • /etc/bashprofile
  • ~/profile

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

$ ls -l
total 0
-rwx------+ 1 user1 user1 0 Oct 27 10:54 data.txt
  • No, it’s clear that user2 does not have read, Scrivi, and execute permissions.
  • sì, il + 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.
  • It’s possible that SELinux provides read, Scrivi, and execute permissions for user2 which are not visible with ls -l.
  • sì, il + at the end of the 10-digit permission string signifies there’s an extended attribute set. This could give user2 permissions to read, Scrivi, and execute data.txt.

Q39. 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
  • 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.
  • 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.
  • 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.
  • 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.

Q40. What file would match the code below?

ls Hello[[.vertical-line.]]World
  • La sezione seguente sarà dedicata alla creazione di immagini di riferimento, this is an invalid file glob.
  • Hello.vertical-line.World
  • Hello[[.vertical-line.]]World
  • Hello|World

Q41. What will be in out.txt?

ls nonexistentfile | grep "No such file" > out.txt
  • No such file
  • ls: cannot access nonexistentfile: No such file or directory
  • La sezione seguente sarà dedicata alla creazione di immagini di riferimento, out.txt will be empty.
  • It will be the contents of nonexistentfile.

Q42. For the script to printIs numeric” sullo schermo, 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
  • Any sequence of characters that includes an integer
  • The user would have to enter the character sequence of ^[0-9]]+$ Only this will prove to be true andIs numericwould 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]+$
  • One or more characters that only includes integers
  • Due to a syntax error it is impossible to get the script to printIs numeric

The regex must not be quoted to work properly.

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

  • history | find cp
  • history | grep cp
  • grep cp history
  • cp history

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

  • for i in $(ls); do ... done
  • for $(ls); do ... done
  • for i in $ls; do ... done
  • 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?

  • |
  • ->
  • \#
  • @

Q46. In the script shown below, cosa è greeting?

#!/usr/bin/env bash
greeting="Hello"
echo $greeting, everybody!
  • a command
  • a loop
  • a parameter
  • a variable

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

  • (( num -gt 5 ))
  • [[$num -lt 5]]
  • (( num > 5 ))
  • num > 5

riferimento

D48. 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)
  • un'
apple
banana
  • B
apple
banana
bananapple
banapple
pineapple
strawberry
  • c
apple
banana
bananappple
banapple
pineapple
  • d
apple
banana
bananapple
banapple
pineapple

riferimento

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

  • $0
  • $# // number of positional parameters
  • $$ // pid of the current shell
  • $@ // 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
  • There is an SELinux security context
  • The sticky bit is set and the file will stay in RAM for speed
  • There is an access control list
  • There is an extended attribute such as immutable set

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

cd -
  • It moves you to the directory you were previously in.
  • It moves you to your home folder (whatever your current working directory happens to be).
  • It deletes the current directory.
  • It moves you one directory above your current working directory.

Q52. What does this command do?

cat > notes -
  • Accepts text from standard input and places it in “Appunti”
  • Creates “Appunti” and exits
  • Outputs the content of notes and deletes it
  • Appends text to the existing “Appunti”

Q53. What is the output of:

VAR="This old man came rolling"
echo "\${VAR//man/rolling}"
  • This old rolling came rolling
  • This old man came man
  • This old man came rolling
  • 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?

  • $INCLUDE
  • $PATH
  • $PROGRAM
  • $PATHS

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

Shall we play a game? yes\no

  • echo "Shall we play a game? yes/\no"
  • echo "Shall we play a game\? yes\\no"
  • echo "Shall we play a game? yes\\no"
  • echo "Shall we play a game? yes\no"

Q56. Given a directory with these seven files, what would remain after executing these commands?

archive.tar
image1.gif
image1.jpg
image2.gif
image2.jpg
textfile1.txt
textfile2.txt

----------

`shopt -s extglob
rm !(*gif|*jpg)`
  • un'
archive.tar
image1.gif
image1.jpg
image2.gif
image2.jpg
textfile1.txt
textfile2.txt
  • B
archive.tar
textfile1.txt
textfile2.txt
  • c : All of this files will be deleted

  • d:

image1.gif
image1.jpg
image2.gif
image2.jpg

Q57. The code below seems to work and outputs “8 is greater than 5”. tuttavia, what unexpected result will tell you it is not functioning properly?

#!/bin/bash
var="8"
if [ $var > 5 ]; then
    echo "$var is greater than 5"
fi
  • There will be no unexpected results. This script works as is and the output will be “8 is greater than 5”.
  • The comparison will not be able to handle floating-point numbers, as Bash only handles integers. So this example will output an error message if the value of $var is changed to “8.8”.
  • There will be a file in the current directory named 5.
  • The variable $var is not quoted, which will lead to word splitting. This script will fail with aunary operator expectedmessage if you change the value of

D58. What is the result of this script?

domanda

  • It removes the directory ‘fooand the files contained within it.
  • It removes all files except those in the current directory.
  • It removes all files in the current directory.
  • It removes all files except those in the ‘foo’ directory.

Q59. Which one is true?

  • SELinux policy rules are checked after DAC rules.
  • SELinux policy rules are checked before DAC rules
  • SELinux policy rules are never checked after DAC rules.
  • None of these

riferimento

Q60. Which does the below command do?

w
  • It doesn’t display information about the users currently on the machine.
  • It displays information about the users currently on the machine.
  • It displays information about the users currently on the another machine.
  • None of these

Q61. Which sed options should you use to change the second-to-last instance of variable to rock so it would read:

A constant is a variable that is a rock that isn’t variable

var="A constant is a variable that is a variable that isn't variable"
echo "$var" | sed _____
  • s/\(.*\)variable\(.*variable\)/\1rock\2/'
  • s/variable/rock/'
  • s/variable/rock/g'
  • s/(.*\)variable\(.*variable\)/\1rock\2/'

Q62. To make a Bash script named script.sh executable, what should you run?

  • exec script.sh
  • chmod +x script.sh
  • bash script.sh
  • source script.sh

D63. How can you create a shared terminal in a Bash shell?

  • schermo
  • screen -X
  • schermo –condivisa
  • terminal -shared

Q64. Wich operator sends the output of ls to a file for later use?

  • ls < filelist.txt
  • ls ¦ filelist.txt
  • ls > filelist.txt
  • ls – filelist.txt

Q65. When comparing items with case, what statement indicates an end to the evaluation block?

  • fermare
  • esac
  • done
  • exit

Q66. To run a group of commands without spawning a subshell, which syntax would you use?

  • (command1; command2)
  • { command1; command2; }
  • (( command1; command2 ))
  • command1; command2

Q67. What are the results of the command with a user named jon?

echo 'Hello, $(whoami)!'
  • Ciao, $(jon)!
  • Ciao, jon!
  • Ciao, $(whoami)!
  • Ciao, whoami!

Q68. How can you copy a directory to another system with compression?

  • tar -ssh usertest19284621.158.1.1 /bin/newfile
  • tar cvzf - /wwwdata | ssh roottest19284621.168.1.201 "dd of=/backup/wwwdata.tar.gz"
  • You can’t compress the stream
  • scp -r directory usertest19284621.168.1.1:/tmp

Q69. To assign the command ls -lah to the shortcut command lh, what command should you use?

  • alias lh='ls -lah'
  • link lh='ls -lah'
  • alias 'ls -lah'=lh
  • lh | ls -lah

Q70. Which statement will print all of the fully qualified .csv files in the home directory or subdirectories while not displaying any errors?

  • find $USER_DIR -name “*.csv” 2>/dev/null
  • find $HOME -name “*.csv” 1>/dev/null
  • find $HOME -name “*.csv” 2>/dev/null
  • find HOME -name “*.csv” 1>/dev/null

Q71. In Bash, what does a # at the end of the default prompt string indicate?

  • that the user is acting as root
  • that the current working directory is the root of the file system
  • that there are updates for the system available
  • that the user is unprivileged

Ultimo strato. What will be the output of this command?

$ ls -l
file10.txt
file1.txt
fileabc.txt
filea.txt
fileb.txt
filec.txt
$ ls -l file[^abc]*.txt
  • UN
file1.txt
file10.txt
  • B
file10.txt
file1.txt
fileabc.txt
filea.txt
fileb.txt
filec.txt
  • C
fileabc.txt filea.txt fileb.txt filec.txt
  • D
filea.txt
fileb.txt
filec.txt

Riferimento The caret (^) symbol here negates matches inside the bracket.

Q73. What is the output of this command sequence?

cat <<EOF
------------------------
   This is line 1.
   This is line 2.
   This is line 3.
------------------------
EOF
  • UN
This is line 1.
This is line 2.
This is line 3.
  • B
------------------------This is line 1.This is line 2.This is line 3.------------------------
  • C
------------------------
   This is line 1.
   This is line 2.
   This is line 3.
------------------------
  • D
------------------------
This is line 1.
This is line 2.
This is line 3.
------------------------

Un impianto di processo è più vulnerabile durante le operazioni di arresto e avviamento. What would be in out.txt?

#!/bin/bash

echo 123446789 > out.txt
exec 3<> out.txt
read -n 4 <&3
echo -n 5 >&3
exec 3>&-
  • 123446789
  • the hyphen symbol (-)
  • 123456789
  • the number 5, which is written to the file using echo
  1. I/O Redirection
  2. Qual è la differenza tra “echo” e “echo -n”?

Q75. Which variable contains the process ID (PID) of the script while it’s running?

  • $ID
  • $#
  • $@
  • $$

Q76. By combining extended globbing and parameter expansion, what would be the value of VAR?

#!/bin/bash
shopt -s extglob
VAR='     This is...     a string of characters     '
VAR=${VAR##+([[:space:]])}; VAR=${VAR%%+([[:space:]])};
echo "$VAR"
  • <pre> This is... a string of characters</pre>
  • <pre> This is...a string of characters</pre>
  • <pre>This is... a string of characters</pre>
  • <pre>This is...a string of characters</pre>

Riferimenti:

  1. What is the meaning of the ${0##…} syntax with variable, braces and hash character in bash?
  2. What does expanding a variable as “${var%%r*}” mean in bash?

Q77. Which operator tells the shell to run a given command in the background?

  • !
  • &&
  • &
  • $

D78. The range of nice number in LINUX system is?

  • -20 a 0
  • -20 a 19
  • 0 a 19
  • 10 a 10

Riferimento

D79. In Bash, what does this expression evaluate to?

echo $((4/3))
  • 1.3
  • 1.3333333333
  • 1
  • 2

Riferimento

Q80. To keep a loop going until a certain condition becomes true, what would you likely use?

  • Se
  • fiore
  • mentre
  • per

Riferimento

Q81. What does this command sequence do?

cat > notes -
  • It creates an empty file called “Appunti” and then exits.
  • It outputs the contents of the “Appunti” file sullo schermo, e poi lo cancella.
  • Accetta il testo dall'input standard e lo inserisce nel file “Appunti” file.
  • Aggiunge testo a un file esistente chiamato “Appunti.”

Q82. Vuoi abbinare palindromi di cinque lettere come il radar, rotore, e principio. Quale opzione sed dovresti usare?

  • sed -E -n '/^(.)(.)\3\2\1$/p'
  • sed -E -n '/^(.)(.)(.).\2\1$/p'
  • sed -E -n '/^(.)(.)(.)\2\1$/p'
  • sed -E -n '/^(.)(.)(.)(.)\3\2\1$/p'

Q83. Per aggiungere un valore all'ambiente attuale, what command should you use ?

  • shell_add
  • Salva
  • echo
  • esportare

Q84. Qual è la differenza tra queste due espressioni condizionali?

[[$A==$B]]
[[$A -eq $B]]
  • [[$A == $B]] viene utilizzato per confronti numerici mentre [[$a-eq $B]] viene utilizzato per i confronti di testo.
  • [[$A==$B]]è il nuovo modo di fare confronto dove [[$a-eq $B]]è la sintassi legacy.
  • loro sono la stessa cosa.
  • [[$A==$B]]viene utilizzato per i confronti di testo mentre [[$a-eq $B]]viene utilizzato per confronti numerici.

Q85. What is the output of this code?

VAR="united states"
echo "${VAR^}"
  • stati Uniti
  • stati Uniti
  • Stati Uniti
  • STATI UNITI

D86. Cosa accadrebbe se eseguissi lo script seguente così come è scritto?

#!/bin/bash
#condition 1
if [ $foo = "bar" ]; then echo "foo is bar"
fi
#condition 2
if [[ $foo = "bar" ]]; then echo "foo is bar"
fi
  • Entrambe le condizioni falliranno.
  • Entrambe le condizioni avranno successo.
  • Motori di ricerca 1 avrebbe successo e condizione 2 fallirebbe.
  • Motori di ricerca 1 would fail and Condition 2 would succeed.

Ultimo strato: The script as written outputs line 3: [: =: unary operator expected. Define variable and assign value foo="bar", and both conditions will succeed.

Q87. Which variable contains the number of arguments passed to a script from the command line?

  • $#
  • $@
  • 0
  • $!

Q88. In Bash scripting, what does theshebang” (#!) at the beginning of a script indicate, and why is it important?

  • It indicates the location of the Bash interpreter that should be used to execute the script.
  • It specifies the version of Bash required to run the script.
  • It marks the script as executable.
  • It helps the system identify the script’s interpreter, ensuring the correct interpreter is used.

Q89. Which variable contains the process ID (PID) of the script while it’s running?

  • $ID
  • $@
  • $#
  • $$

Q90. If a user wants to execute script sh without a shebang fine or execute permissions, what should the user type?

  • A shebang line is required to execute a shell script.

  • ‘bash script.sh’.

  • 'exe script.sh'.

  • Per eseguire uno script di shell sono necessarie le autorizzazioni ExecuteExecute.

Q91. Quale scelta è l'output più probabile del comando composto mostrato di seguito?

cat -n animals | sort -r | head -n 5
  • un'.
	1	Ant
	2	Bear
	3	Cat
	4	Dog
	5	Elephant
  • B.
	9	Ibex
	B	Hippo
	7	Giraffe
	6	Fox
	5	Elephant
	4	Dog
	3	Cat
	2	Bear
	1	Ant10	Jaguar
  • c.
	Jaguar
	Ibex
	Hippo
	Giraffe
	Fox
  • d.
	9	Ibex
	8	Hippo
	7	Giraffe
	6	Fox
	5	Elephant

Q92. Quale dei seguenti non è un nome di variabile Bash valido?

  • $HOME
  • my_var
  • 1var
  • !

Q93.In Bash, creare un comando di una riga che trovi ricorsivamente tutti i file con l'estensione “.txt” estensione in una directory e nelle sue sottodirectory, e conta il numero totale di righe in quei file. L'output dovrebbe visualizzare solo il conteggio totale delle righe.

Quale dei seguenti comandi Bash di una riga esegue questo compito?

  • find . -name "*.txt" -exec wc -l {} \; | awk '{total += $1} END {print total}'
  • grep -r ".*\.txt$" | wc -l
  • find . -type f -name "*.txt" | xargs wc -l | tail -n 1
  • find . -name "*.txt" -exec cat {} \; | wc -l

D94. Qual è la differenza tra i file > e >> operatori di reindirizzamento?

  • > overwrites the contents of the target file, while >> appends to the end of the target file.
  • > redirects input, while >> redirects output.
  • > is used for standard output, while >> is used for standard error.
  • > is a unary operator, while >> is a binary operator.

riferimento

Di Helen Bassey

Ciao, Sono Elena, uno scrittore di blog appassionato di pubblicare contenuti approfonditi nella nicchia dell'istruzione. Credo che l’istruzione sia la chiave dello sviluppo personale e sociale, e voglio condividere le mie conoscenze ed esperienze con studenti di tutte le età e background. Sul mio blog, troverai articoli su argomenti come le strategie di apprendimento, formazione in linea, orientamento professionale, e altro ancora. Accolgo con piacere anche feedback e suggerimenti da parte dei miei lettori, quindi sentiti libero di lasciare un commento o contattarmi in qualsiasi momento. Spero che ti piaccia leggere il mio blog e che lo trovi utile e stimolante.

Lascia un commento