Ch2 Shell Scripts Exam

  1. Which of the following steps is not performed while creating a shell script?

    • Create a file with commands 
    • Make the file executable 
    • Login as root on the server console 
    • Put #!/bin/bash as the first line
  2. The first line in a shell script reads:

    #!/bin/bash

    What does it signify?

    • It is a comment 
    • Name of the editor used to create the file 
    • The executable (shell) to use to run the script 
    • The script requires root login
  3. The bash script_file command can be used to directly execute a shell script.

    True or False?

    • True 
    • False
  4. Which of the following is placed before a script name to execute it from the current directory?

    • ./ 
    • #! 
    • !! 
    • //
  5. Instead of specifying the current directory, it is better to place the script in a location that is included in the __________ variable.

    • SCRIPTS 
    • ENV 
    • PATH 
    • GLOBAL
  6. An ideal place for a regular user (not a super user), to place their shell scripts would be:

    • /usr/local/sbin 
    • /bin 
    • /home/james/bin 
    • /sbin
  7. Use of setuid permission on scripts is the best way to specify permissions.

    True or False?

    • True 
    • False
  8. A user has written a few scripts for private use. Which of the following commands should be used so that no one else has execute permission?

    • chmod a+x script_file 
    • chmod -R 755 script_file 
    • chmod u-rx script_file 
    • chmod u+x script_file
  9. Which of the following commands will produce the same result as start=`date`?

    • start=%date% 
    • start=(date)
    • start=date 
    • start=$(date)
  10. The __________ statement can be used to gather information from the user running the script.

    • seq 
    • if 
    • read 
    • for
  11. What will the following command do (select all that apply):

    read -p “Enter data> “ test

    (choose two)

    • Print the input on local printer 
    • Work the same way as the type command 
    • Store user input into a variable called test 
    • Show a prompt along with blinking cursor
  12. The command read -p will not capture the current position of the mouse pointer.

    True or False?

    • True
    • False
  13. Conditional statements can be used to determine which of the following?

    (choose three)

    • If the file exists 
    • If two numeric values match 
    • If two strings match or not 
    • System runlevel
  14. When will the condition test -n STRING be true?

    • If the length of STRING is zero 
    • If the length of STRING is nonzero 
    • Never 
    • Always
  15. In shell scripts, the conditional statement if must always end with:

    • elif 
    • False condition 
    • fi 
    • then
  16. The return status from a command is 1. What does this indicate?

    • Command did not execute successfully 
    • Command executed successfully 
    • Command is still running in the background 
    • Calculation done by the command yields the result 1
  17. The jamie user already exists in the system. The command grep jamie /etc/passwd displays one user record. Running the echo $? command immediately after the grep command would result in what output?

    • 0
  18. Which of the following will not handle bad user input properly:

    • Checking the command’s Standard Output 
    • Checking the validity of user input before passing it on to the command 
    • Checking the value of the $? variable using an if statement 
    • Checking the return value of a command directly in the conditional part of the if statement
  19. The joanne user wants an email sent when her shell script is executed successfully. Which of the following commands in the script can do this?

    • cron job will send an email by default 
    • mail root 
    • mail joanne 
    • echo $mail
  20. The __________ statement is most useful in performing an operation on multiple items.

    • test 
    • many 
    • read 
    • for
  21. What will the following statement do?

    for name in `cat /root/users`

    • Report an error 
    • Run for two values; cat and /root/users 
    • Assign to the name variable each value in the specified file 
    • Get into an infinite loop
  22. The output of the command seq 10 10 30 will be:

    • 50 
    • 10 20 30 
    • 10 10 30
  23. The ___________ command is used to print a sequence of numbers.

    • series 
    • seq 
    • list 
    • num
  24. The statement if [ -d file ] will be true, if the file:

    • Is writable 
    • Exists 
    • Is executable 
    • Is a directory
  25. Which of the following file test statement conditions is not correct?

    • -e filename tests if the file exists 
    • -x filename tests a file to determine if it is executable 
    • -w filename tests a file to determine if it is writable 
    • -d filename tests if the file is in the current directory
  26. A user wants to execute a script called test1_script. What type of permission does she need on the test1_script file?

    • Write only 
    • Read only 
    • Read and execute 
    • Read and write
  27. Command substitution cannot be used to insert the output of a command as another command’s argument.

    • True 
    • False
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments