You are on page 1of 200

c 




c    c
  
     

{   

  
 

   
 

 

    

{ 
  
 
  
 

$ sort -r userlist

a 
    
  

  
 
   



{ 
 
   
    ? 
? 


$ ls -l | less

a 

  


  
   ½  


   
 
 

   


           
   

   

 
    V 

 
  V


 

$ cp list list.bak; cat list.bak

|


 
 
 

  
   

× 

 ½
× 

½
× 
½
×  ½
×

½

 ½
{ 

 ½

    
 
  







   
 


 
 

{ 
    


 
      
 


 
  
 
   
   
   
 { 

     
    !  


!






{ 
 
  
 
 
   

{     

" #    
 

   
 $
%   
  
   $
% 
    
     $
%

 
   ½
{ 



½
      

  

 

  
  

  
    
 

{ 
     ? 
 
 
 

{     

"&& % 
   ½
{ 


½
      
  


 


 

{ 
  
 
    


{     

" ' 
 ½
{  

½
         
    

  


{ 
     V

    
 
   

{     

"
(

)*|   
*
  ½


½


  


 
   

  
 

{ 
  
 © 
 
 
    

 

{     

" *(

*+
,-./01/0
"(



 
 


 
       2 
  



 
      3       



 ½

{ 
 
 
     




{ *


     

     
  







$ echo Tours \& Accommodation


Tours & Accommodation
$

Î 

å          



    
  4

5 6

- 7

2 
 
      

 
8 7   
    
  
 
9 7   
      



 
/ 7   
       

 

¦ 

   



     






  
       

  
 
  

{        



 

 {  


       
 
3  

{    


        *
 


 

 
 
   
 
 
  

     


  
  
      
    


  


  
    
   

 



  
  
  


 
 
    
  

 
 
 

     


   
  

 
 
  

(
 
  

     3 6

× 

 
×  
 
× 

  
×
  
×
     
×    
× 
 
  

  




     
½
!
 
 
!   


 
   

: 
  ’ ??
  
 
  
 
      ½    
   

     
    *    

: 
      
   ´ V © ?  

  && &  & 8
   


           



 

 
 ½     
      
  
  



: 
  
  | 

 ’     |  

  & & 
    

           

   


 
 
 ½       



     
* 

: 
  
     
    
    

              

    
    

 
 
     

 
 

     

: 
  
  

   0
  
     
 
  
 


  
 
 
  
   

 



          
    

 
       


     

 ½3 
½  
 ½ 
       
 


   

      

: 
            ©  

  
   

  
 
     3   

  

 
   
 



{  
  


        



 


5   


    
      

    

     
      



Î 

 


  

  
 4

5 6

- +
8 )
9 ;
/ $
¦ 

{ 

  <+=  

  
 

Option 1 is correct. The ampersand symbol (&) is used at the end of a command, to
run a job in the background. Jobs in the background are assigned a job id number.
You can you can use this number to foreground the job again.

Option 2 is incorrect. The pipe (|) special character allows you to use the output of
the command on the left of the pipe as input for the command on the right of the
pipe.

Option 3 is incorrect. The semi-colon (;) is used to combine separate commands on


the same line. Commands on the right of the semi-colon are only interpreted once
commands on the left have been interpreted and executed.

Option 4 is incorrect. The backslash (\) is used to prevent special characters from
being interpreted in such a way that their literal values are used in stings. Also, you
can continue your command on a new line by typing a backslash before pressing
Enter.

Î 

@   
 


 
  

5 6

-
  )"<
& & 
=
8 >&  
9   ?-89=

 % 
/ @)A

A

¦ 

{  "<
& & 
= 

 
  {  
  
 



   


Option 1 is correct. In this example of command substitution, the command cat


/etc/hostname is processed before the grep command is executed, so that its output
can be substituted into the grep command.

Option 2 is incorrect. This is an example of tilde substitution. The path ~/documents


expands to the documents folder in the home directory of the current user.
Option 3 is incorrect. This is an example of brace expansion. The code
server{1,2,3).easynomad.com is expanded as: server1.easynomad.com;
server2.easynomad.com; server3.easynomad.com.

Option 4 is incorrect. This is an example of filename substitution. The code ls * lists


every file in the current directory.

A     

a 
B 
 

   


  

     

  

: 
 

 
     
  

 

   
 
      

Î 

å         




  4

5 6

- 7
 
 

8 7
 
* 
 2 
9 7
 
*

   
/ 7
 
*

  
   


¦ 

{   





     
 
 
 2 

{ 
 
   
 
   B  
 
 


½{ 

 ££      
 
 ££    
2  
!        

 
 ? 
        7
  
  ? 
    <   
 2 { 
 

  

$ ls userlist && sort userlist


userlist
BAKER, Daniel
CARUSO, Maria
GARZA, Teresa
LOGAN, Greg
MANEROWSKI, Sarah
NOVAK, Nicholas
NOVIALLO, Glen
OSWALD, Sam
PASCUCCI, Vince
REILLY, Molly
STROTHER, Tanya
WADE, Debora
$

    


 


 ? 
 

 !   
  2 7
  
    
  
 *
    

$ ls userlist && sort userlist


ls: userlist: No such file or directory
$

a 
  ½ 


   
      
  


 

  
     


 2  



 
 ? 
  
 
  
     
 V
 
 

$ ls userlist || touch userlist


ls: userlist: No such file or directory
$

 ? 
    

  

  

  V
 * 

$ ls userlist || touch userlist


userlist
$

a 
 
 
½
{  


   


  
 


{ 
      
  
 
  


 
 
   
 
  
   

    
 

  
   C 
$ {sort | grep 'Mexico'}

a 
   
  

 
  
 

 
        
 
  D   
 

$ {sort | grep 'Mexico'} < flights > mex_flights


$

a 
 
  
! 

 ! 
 

{ 
   

 
  
   
 

@

  
   
 
*
   
 

{ 
    


         
 

            
   
 

$ (sort | grep 'Mexico') < massivefile > mex_info


$

Î 

a 
  

 
 

 
  

-

 å    *
   
   




     


    4

5 6

-
 
)) 
-

 % 

8
 
++ 
-

 % 

9
 
%% 
-

 % 

/
 
) 
-

 % 


¦ 

{   ))


  
      

   
      
     
 


Option 1 is correct. You use the double pipe to make a command conditional on the
unsuccessful execution of a previous command.

Option 2 is incorrect. The && conditional execution symbol ensures that if the attempt
to list the hostname file succeeds, it will get overwritten.
Option 3 is incorrect. The >> redirector is used to append output to a file.

Option 4 is incorrect. The I symbol pipes the output from one command into another
command as input.

X      

@
      
  
  
 
    

å   
 
    
   
    

    
 

 
 *


      
 

a 
    
    

{      
 
  
|@

Î 


              
|@ 4

5 6

- {  


8 { 

   
 
9 { 

       
   
  
/ a 
   

¦ 

   
|@     


 




       
   
  

a 


   
  
    å   
 
     

{   
 
  
      

{    


   
 

   
   
 

  
      

{   

 
     

{     
    
      

   

 

  ½! 

 
!
 
 
 
  
  


{ 
     
  
 E  

 /bin/ksh

{  
 
        &&
&   
 *    
 {   

 
        


 


 /bin/ksh
ls /usr/shared/tours || mkdir /usr/shared/tours
touch /usr/shared/tours/tourlist
echo tour directory and tourlist file created.

5  *  

  

  
 
 

 
 
 a 
      
   
        
  

Î 

  


 
       

5 6

- |   


|@ 
8 |          
9 |    
 
  
/ {    
        
 

¦ 

|   
|@ 
 
 
  { 
   
       
 

Option 1 is correct. Because shell scripts are simple ASCII text files, you can easily
create them in a text editor such as vi or emacs.

Option 2 is incorrect. Shell scipts are interpreted by the command interpreter, so they
don't contain binary code and aren't compiled.

Option 3 is correct. Because shell scipts are executed, either one or more of the
owner, group, or other executable permissions must be set.
Option 4 is correct. The first line of a shell script consists of a hash symbol followed
by an exclamation mark and the absolute path to the command interpreter that will
be used to execute the script. For example:
#!/bin/bash

 

a 



 B 
 
 
    

  
  
 
   

 
  a 
      2 



   
  


    

        

 
  

a 
 
 
 
 
   
 



 
a 
B  
 
  

      
       
 

a 
   
 
 

   

  
 
a 
        
 
  


 


{     

){  )

)    )

)     )

)A     )

)X      )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        


) )  ))

        c



    
¦  


     
    

      

{  

     
  
   
  


: 
*

    
     E  



   
  
 
 
   






a  
   
!  
!
 
DD 

Î 

a     E  


       

 
 
   E   & &   
  

  


MISSING CODE

¦ 

a  ’      E  


       

{ 
     
      
  



{           



  
 

  





 /bin/ksh
clear
echo "Please enter the name of the new travel package: "
read PNAME

a   

     

 &&

  

A  A
A  A      

   

a    
   
 

 /bin/ksh
clear
echo "Please enter the name of the new travel package: "
read PNAME
ls /usr/shared/$PNAME || mkdir /usr/shared/$PNAME
cd /usr/shared/$PNAME
mkdir bookings
mkdir info

a   
       
 !     
 

 
    

a    
   V
 

 /bin/ksh
clear
echo "Please enter the name of the new travel package: "
read PNAME
ls /usr/shared/$PNAME && mkdir /usr/shared/$PNAME
cd /usr/shared/$PNAME
mkdir bookings
mkdir info
touch /bookings/$PNAME_bookings
touch /info/$PNAME_accom
touch /info/$PNAME_flights

: 
 
     

 
  
   
  

 
 
 

 /bin/ksh
clear
echo "Please enter the name of the new travel package: "
read PNAME
ls /usr/shared/$PNAME && mkdir /usr/shared/$PNAME
cd /usr/shared/$PNAME
mkdir bookings
mkdir info
touch /bookings/$PNAME_bookings
touch /info/$PNAME_accom
touch /info/$PNAME_flights
echo "Files and folders for $PNAME created in /usr/shared."

 * 

     
     
    
    ? ?
 
 * 
   

DD 

{ 
 

   *
     {  
 
* 

  

$ ls -l
total 2
-rw-r--r-- 1 vincep vincep 326 Feb 11 11:56 add_pkg_files
$
   
         

 

×   * 


×     * 
×   

a 
              

       
  
 
 
    

{ 

   
        V 


$ chmod +x add_pkg_files
$

         


    
 {  
 G 1  
      G   

1
  
 
   

{    
    *      * 
   

  

#*

  
     
    *

 
 
      

a 
       *  


$ chmod 755 add_pkg_files


$

#*

 *
   
    
 
     
   
     5   
  *


 
    



 
       *  


$ chmod 770 add_pkg_files


$

Õ ? ?



 

       


$ ls -l
total 2
-rwxrwx--- 1 vincep vincep 326 Feb 11 11:56 add_pkg_files
$
Î 

  
 
 
   *   1/G  
 
    4

5 6

- 
8 5     
   
9 5 
   
/ 5 
  


¦ 

 
    
  
  
 ! 
 
    

Option 1 is incorrect. In this example, general access to the file ± as represented


by the 0 in the permissions octal ± is denied.

Option 2 is incorrect. In this example, the permissions of members of the group


that owns the file is represented by a 4 so they can read the file, but can't write to
it or execute it.

Option 3 is correct. The file owner's permissions are represented by the 7, so they
have full permissions to the file and can execute it.

Option 4 is incorrect. File system permissions aren't affected by whether users are
logged in locally or remotely.

Î 

   


  

   

5 6

- (  


8 :  
9 H 
/ #
  

¦ 

a 

       

      

   
   
Option 1 is correct. You can set permissions for anyone that tries to access the
file. If you want everyone to be able to read a memo in a shared directory, you
would set the read permission in the third permission set.

Option 2 is correct. By default, the user who creates a file owns it, and usually has
full permissions to the file.

Option 3 is correct. By default, the user who creates a file is part of a primary
group that also owns the file You use group permissions to control who can
access a file and what they can do with it.

Option 4 is incorrect. You can't assign permissions at local login level. Instead you
use the group ownership of files to control access.

A      

a 
 
   

×      


×     
×      

    
Ú       
  
  a 

      
      
 

    &


 

     *    
   
 
      
      
      
 
    

   
     

   
{ 
     
 
       
       
  3 
    
 
   

         


{ 
       
   

        

{  
DD          © ? 

 
 

{ 
   

   
 

 {   
        
      
   
 
$ ./add_pkg_files

a 
     
  
    
  
      

$ ./add_pkg_files &

a 
        {     E   
 
’    © ?           
 

$ /bin/ksh add_pkg_files

 

          
       
 * &       

 
    
    { 
     

 

$ add_pkg_files

  *


     
  
      
 V{ 
  
  

     
3 

a 
* 
    
        

       

 <=

$ source add_pkg_files

Î 

a 
 
  
   



    
    4

5 6

- Õ
  

   
8 Õ
  


   

9 Õ
    
 
 
/ Õ
        

¦ 
a 
 
 
  

   


   
    
 
 

a  
 
  

   

 
  
    
I6GG  5  -8

a 

    
  
      
   
/6GG 

$ at 6pm Oct 12 add_pkg_files

a  V
 
  

 


a  

  & &  
    
    

  

   

{   V
 

 
   & &  

 
 
 
B      

$ cron

a  ’V
 
  
 
 
 
 

  
     ’V
  3 

 B 
   



 -J

$batch add_pkg_files

Î 

C
  
      

5 6

-

8 
 
9  

{
6

 Õ      


  
7 Õ  

   

@ Õ  

   

¦ 
a  

 


     

 



 

 
 
    
   
  

The at command allows you to specify the time and date at which a script will run.
You can use a variety of formats, including keywords such as "noon" and "today".

The batch command is useful if you want to run scripts at times when they won't
interfere with system performance. It runs commands or scripts when system load
levels drop below a specific amount. The amount will vary according to your
system.

The cron command allows you to specify the interval at which a command will
repeat. It can be set to recognize minutes, hours, days of the week, days of the
month, or specific months.

Î 

a 
  



 & &&   


   

  a 
        

 
  4

5 6

-
  
8 &
  
9 & &
 
  
/   
  

¦ 

{   
  
 

 
  
     

Option 1 is incorrect. This method executes the script in a subshell. It is used


when the location of the addfile.sh file is listed in the $PATH variable

Option 2 is incorrect. The ` syntax only allows you to execute the addfile.sh file
in a subshell. It is used when the location of the file is not listed in the $PATH
variable.

Option 3 is incorrect. This method launches a subshell in which the script is


executed. It's useful if you need to set options for the subshell.
Option 4 is correct. The source command reads the contents of the referenced file
directly into the current shell. It's useful if you want to apply changes to your
.profile file during your current session.

 

{  
        
 {  
  


   3 
a 
  

  

  
     

a 

                   7  
  
   
 
  

    

     V              

       

     

 

 

! "   c
  
¦     

{



 
   
  
   
   

 

 
 


    
  
  



 

a  
 

 
   
 
 
 

B    
 

a     
   
  

  2   
  
 




a 
        
  
  2 
 

 !
  !  

  


a 
  
  © 
  

  
  
   { ©  
 
 &&
a  *
 
   
   © 


a     
 ©  
   
 a   
V 
 

  
    

 {   
 
 ©  
  
  
 

 : 
 

   ©  
     
 

{   *       E    

& & 

{ 

    

  
    E  
 © 
V 

!

    !   2 

 
   

  


Õ    


  

         


{     

){  )

) )

))

) )  ))

c
   
    

¦  


      
    
 

 c       

  
 
 

 !    

  

a  
    

   

*    




   
 




 
  ½ 

{          ? 
 
 
  

  V
  
     7
  





      
$ ls -l /home > listing ; cat listing
lrwxrwxrwx 1 root wheel 9 Oct 30 13:53 /home -> /usr/home
$

 
     


 ½      
 


      


a 
         

   
      
     
   

 



a 

 

   

  

$ echo This is a very long line of \


> text, wrapped with a backslash
This is a very long line of text, wrapped with a backslash
$

Î 

C  


 ! 




   

  7
  
 


    
    
     
  


a      

½

|  
     ? ?
  ? 



MISSING CODE

¦ 

a ? ?  ?       ? ?


  ? 



|   

 
  
 
  *  


    7
 
 @   
   
       

a 

 

     




½{ 
   
  
      
 

$ ./myscript.sh &
[1] 34030
$
Î 

 
 
   
 
4

5 6

- a 


 <$= 


    
8 a 
 

 <&=  


  
9 a 


<+= 
  
 
/ a 
   <;= 



    

¦ 

a  

  
 
 

     
   
  
 
 

 

  
 

Option 1 is correct. Provided you precede it with a backslash, you can use the Enter
key to continue long commands on a new line. The shell will run your command as
one long line, ignoring the backslashes.

Option 2 is incorrect. The forwardslash does not prevent special characters from
being intepreted. It is used in the syntax for describing the filesystem.

Option 3 is correct. The ampersand allows you to run commands in the background
on idle processor cycles, leaving you free to continue working in your current
session.

Option 4 is correct. You can use the semi-colon to combine commands that execute
consecutively on a single command-line. This is useful when the first command will
take a long time to complete.

A     

@   
   
 



     
 

     
  
 
 

: 
   

   
    2 
  
 

    


 
 2

Õ
       

exit status  
    *    {  
 
  


  



   

 G   H




    

     

    
     
  
       

C   



     
  
       

  
  

6

×   ½
×  

½

   ½
 

 
    

½  
 
     

 !
 2  

    ½
 

 
   



½  

      
  ! 
2  


*        


   
      

: 
  
    
     


   

  
  

Î 

  


 
       
  

5 6

-  2  


 



    
8  
 G 



  
9 @   
  
    

 
   
 



/ @   
  
    
  
    




¦ 

 2  


 



     

 
 G 

    @   
  

    

 
   
 



Option 1 is correct. Any non-zero exit status is a failed command. The range of
possible non-zero values for the exit status depends on the command that you
execute, and the shell you use.
Option 2 is correct. If the last command to execute completed successfully, the value
of the $? Variable, in which the exit status is stored, will be 0.

Option 3 is correct. Depending on the conditional operator you use, code will execute
only if the previous command executes successfully, or only if the previous command
fails.

Option 4 is incorrect. You can use the test command to return an exit status after
testing for a particular value, but conditional execution only operates on the exit
status of commands, not their results.

Î 

a 
 
 
  
     
  *
 


   

 


 4

5 6

- ls hosts && touch hosts


8 ls hosts || touch hosts
9 ls hosts ; touch hosts
/ mv hosts oldhosts && cat oldhosts && touch hosts

¦ 

{  
 
         

 a 
 ££ 
  

     
  
 

    
 

Option 1 is incorrect. The ? hosts command will have an exit status of 0 if the host
file exists, and the  operator will cause the hosts file access and modification times
to be updated.

Option 2 is correct. The  operator will execute if the hosts file doesn't exist and the
? command returns a non-zero exit status. This will cause the touch command to
execute and create a new hosts file.

Option 3 is incorrect. The  operator merely allows consecutive execution of


commands. The execution of the command to overwrite the hosts file is not
dependant on the exit status of the command listing the host file.

Option 4 is correct. It is safe to overwrite the hosts file if the command that renames
the original file, as well as the command that prints the contents of the renamed file,
complete successfully.


command 1))command 2++command 3

Î 

#*

 
  



        
 
           

     

 
   

   

|  

 
    


 
    
 


? ?  ?? MISSING CODE
V  ?? ’V ? 
MISSING CODE  ?   
  

¦ 

a  ££ 


   V  ? ? ’V ?

  ?  ? ?


  

Î 

|  
      

     
 
 



? ?  ?? ££ V
 ?? ’V ?
 MISSING CODE  ?   
  

¦ 

a   


     ? 
?V?  V 
   © ?
    
 
 2  


X #    

@   
   
 

   

 
 
!
 
*
 
 
     
   
 
 

{ 
    
  * 
   

     
  
a 
   grouping

a 
  
  
 
  

code block.{   


  
  
 
<    

  
  
 
 
  


   


{ 
    

  

   

a 
 
       
6

× 
½

×  
½½

 ½

a 

½
  
   
      
   ½½
a 
 
½½  
   
   
 <

  

   
 * 

{ 


  
 
 <      

< 
 
      






   



    
   *
   
 
  

Î 

 
 
        4

V V  V   ££ ? 



V V  V   ££ ?

5 6

- {   


    
 
8 { ? 
      /etc   
9 { ? 
      
 V   
 
 
/ {   
  
 

¦ 

@   
    
 
Option 1 is correct. Code within parentheses is run as a separate process in a
subshell. You can set local environment variables within the subshell without
effecting your main shell session.

Option 2 is incorrect. The variable that stores the current working directory for the
shell in which the ? command is executed is not affected by the command to move
to the  directory in the subshell.

Option 3 is incorrect. The execution of the ? command is conditional on the


successful completion of the entire block of code within parentheses.

Option 4 is incorrect. You can include comments in shell scripts by preceding each
line of comments with the # symbol.

Î 

   


 

    
   

5 6

- - 
8 
9

/ 

¦ 

a  
 

 
  
   
 
 

  


Option 1 is incorrect. The - symbols are used by the shell in pattern matching
operations to specify character ranges.

Option 2 is correct. The o symbols group commands into a single code block for
execution in the current shell.

Option 3 is correct. The  symbols group commands into a code block that is
executed in a subshell. This is useful if you want to avoid altering environment
variables in your current shell, for instance.

Option 4 is incorrect. The  symbol is used to enter multiple commands on the same
line. However, the commands are executed in sequence, not as a code block.

Î 
| 
 * & &
       
  
    
    
 
 



              
   
  4


V  ?  ? ?  
££ V    ? © ?

5 6

- &
& 
8 & &
9 && 

¦ 

 
         & &

Option 1 is incorrect. The command that changes the directory to /var/logs runs in a
subshell. To run the code in the current shell, thereby changing the current directory,
you need to remove the braces, as shown here:
V   V  
 

The command that changes the current working directory to   is part of a
code block enclosed in brackets  so it will execute in a subshell. As a result, it has
no effect on the current shell you're in.

Option 3 is incorrect. At no point does any code change the directory to  
± either in the current shell or the subshell ± so this can't be the current directory.

 

{  *
  
 

 a 




 
  ½        



 ½
    
   
 ½

a 
   
 
   

 
   

   
a  



½  



  
 

 
  

½ 
 


  
 



a 
 
      
    
 
   a 
½
  
      

 
½½  
   
 
{     

){  )

)    )

) c       )

)A      )

)X #    )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

  c

    

¦  


   
 
  




 c     

C 


 ! 

     


   
      
    
 

   
 

 
          
 ½     

       
  
å       
     

   

a 
          
 
        

 6

× 

½
× 
½
×  

  ½

   ½
a   
   
 
      

 
  
  *     
         
   ½
a   
   
 
   

  
 : 

    ?
 
 
    
  

 

 

   

   
      ½
a   
   
 
      

 
 

  



   

 {    
   

 
           *3 
      


{        V?’’   



 V?’’           !     
   
 
V  a 
V?’’   
V?’’
  

 
       V?’’ 
  
 
   

$ set -o noclobber
$

Î 

#*

 
 
 

  a *   
       

 * 
  
 



|  
           
 

 
 

 


 ?    
V
?V?  MISSING CODE
 ?

¦ 

a   


      
 
 
 

 

a  

  
 
     *   
$ mail ±s "Guess what"
vincep@localhost < email.txt
$

Î 

#*
 *  
   
  V
a *
      
  
  
 
  


|  
  
        

 
 
 


 V MISSING CODE V

¦ 

a   


    

  
 
 
   

{        V


 
 7
 * 
      *     

$ man exec > exec.txt


$

Î 

C
      
           

5 6

- %
8 '
9 %%

{
6

  
  

 
 
7      

 
 
@   
 
  



¦ 

a  % 


       

 
 ' 
 
 
 
  


 %% 
  
   


 
   
You can use redirection to document your system by redirecting the output from
commands to a file, as in this example, which records the network interfaces
configured for a system: V   

`


Several UNIX commands accept files as input. For instance, you can redirect a text
file called report.txt to the mail utility and send it to Fred with the following command:
   
`


Appending command output to an existing file is useful for troubleshooting.


Scheduling regular execution of the following command enables you to monitor
which kernel modules are loaded on a Linux system:  
  `

A $ 

:    
 !
     
<  
   & 
<&5= B  
 
      a 
    


 

7       *
  
 

   &5 B 

    ! 
  
 

  


 

     
     



6

× G
× -
× 8

U
Ú   G 
  
 
* 

  


         

Ú   - 
  
 * 

   
  
 
 
 

 
 

  
      
   

  
 
A
Ú   8 
  
 * 

    

   

 

 

    
     
  
 

  
 

 

  
      
  
    

a 
       
 

     
     
   
! n 
    6

× '+ 
× %+ 
× '
 
× %
 
× %%
 
× %)
 

÷
a '+    

  
     : 
  
£ 

   

 
÷
a %+    

  
     : 
  
£ 

   

 
÷ ÷
a  '  
 
   
        
÷ ÷
a %  
 
   
            

       
   { 
 


 

     V?’’

  V?’’

÷ ÷
a  %%  
 
   
        {     

 
    
     
 
   
÷ ÷
a  %)  
 
   
           
V?’’

  


Î 

  


 
         

5 6
- a 2>| 
   
*    


 
8 a 2>   

  
 
9 a >&2   

  

 
/ -%   

  
 

¦ 

a >&2   



  

    

 
  2>,
   

  
   1>.

Option 1 is incorrect. In fact, this option allows you to overwrite existing files with
standard error.

Option 2 is correct. This is useful for for printing error messages.

Option 3 is correct. If your standard error is connected to a printer instead of the


display, this would be a quick way of printing command output.

Option 4 is correct. Instead of the output going to the screen it can be redirected to a
file using 1>

Î 

#*

 
  © 
 
 
 
 
    

 


   

|  
   
        


 
 
 


©      MISSING CODE
   MISSING CODE 

¦ 

a    



  
 

Î 

|  
        

  
 

 


©        
MISSING CODE 
¦ 

a    



  
 

Î 

C
 


    
  


5 6

- G
8 -
9 8

{
6

 |

 
7 |

 
@ |

 

¦ 

{      



 


 G     





 -
     

 


 8

Standard input is associated with file descriptor 0, and is usually mapped to the
keyboard. Typing commands with a keyboard is the most common way of interacting
with the shell.

Standard output is usually mapped to the screen. Most programs use standard
output to print usage messages or the results of commands.

Standard error is associated with file descriptor 2, and is usually mapped to the
screen ± but it is sometimes useful to map it to a printer, to record errors.

X    

|        

 
      


a    
here document

å  
     
   

! 
 


    
   

a 
            
  6
×  ''
,
 !
×  ''
,
 !

V ÷  ÷  %÷



   
 ''
,
.    



     <    
   


 *   

 
 
V ÷  ÷  %÷

   
 ''
,
.    



     <    
   

 
  

 
 

{ 
 
   



 
  3  
 



#*

 
 


  
  

 

 
a    
  
    
  (Ú

 
 

a  
  
   

$ telnet << END


>

{   



   
  

<-KG-GG89
 
|   
  
  


 
 

$ telnet << END


> open 190.100.2.3

a  
  
 3 



     
  

 
 
 AA
 
   A
 A

{   

$ telnet << END


> open 190.100.2.3
> gregl password
{    
            

      
a 
  · 
 
  

a  




$ telnet << END


> open 190.100.2.3
> gregl password
> mail ±s "remote userlogs" gregl@190.100.2.1 < /var/log/userlog
> quit

{    
        
 
    
   <  
  !
  

{    

       

$ telnet << END


> open 190.100.2.3
> gregl password
> mail ±s "remote userlogs"
gregl@190.100.2.1 < /var/log/userlog
> quit
> END

Î 

| 
 * 
    
 
  
 A(ÚA

 
 

|  
      


 
  
     


 MISSING CODE   

¦ 

a   


  

 

    
  

Î 

 
 
    
  4

5 6
- { '' 
 
    
 
 
   
8 å  
 

   
9 {    
    




/ {  
      (Ú

¦ 

a  '' 


   
 
   
   å
  
  

 
   
    
 
   





Option 1 is correct. Automatically stripping tabs from your here document allows you
to improve its legibility.

Option 2 is correct. Most interactive command line programs, such as telnet or ftp,
can be automated using here documents

Option 3 is correct. Here documents start with a command interpreter that loads a
command to read and execute the rest of the shell script.

Option 4 is incorrect. Although END is frequently used as a terminator in here


documents, you can use any string as a terminator.

 

C 


 
  
    
a 
  
 to
 
 
  
 from
 

:    
  
   & <&5= B { 
 
    
      

 <G=

 <-=



 <8=a 
      

å   
   
  
   

{ 

       
 
 
?

{     

){  )

)    )

) c      )

)A $ )


)X     )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

        c



    

¦  


   

  
 
  
  

        

a 
 
    
     

 
    

: 
       


         



 {    
 
 
      
  

 *   

{  



   

×
 ½
× 3 
½

 ½
a   
 
 
  
 

: 
      
         
     

    AA
·   ½
a  ü 
 
 
 



: 
   © ?ü    
  
  G-   
 GK!    

a 
    

  
   3


½%&        6
× ,.
× ,".
× ,"" .

%V&
a    ,.       





 
3



: 
   © ?-     
  
  G- G/

 G1!    


%&
a    ,".       





  

 3



: 
   -V    
  
 

D



D


D !    
%V&
a    ,"" .       





 
 
 
 3

a 
  
  
  



: 
   ?-  !"    
  
  - 8
 9 I 1
 0!    

Î 

|  
        
  
    
   
   
 
 
  


? MISSING CODE

¦ 

a -#  -#    


  
 
   

 
 
  

  


     3

  
!
 2
G
 K{ 

  

 <@= 
 
     
   


$ ls [a-z0-9]*
120415_log report1.txt report3.txt staffdata
120603_log report2.txt searchdata
$

a 
   
    

 
½

: 

     
       
don't 
  

$ ls ±l *[ 0-9]
120415_log report1.txt report3.txt staffdata
120603_log report2.txt searchdata
$

5
 
 
  
*     
  a 
 

*          
   ½ 



{ 
       
  




$ echo ~
/home/vincep
$

a 
  <>=

          6

× >
× >
× >
× >L


{    
    
   *"    





{    >  
  
  *    

{    >  
           

{    >L  
       

Î 

 
  <>=  4

5 6
- cd ~
8 cd ~$HOME
9 cd ~-
/ cd ~Fred

¦ 

{ 

     

Option 1 is correct. In this case, the command changes the directory to the home
directory of the current user.

Option 2 is incorrect. The tilde substitutes for the $HOME variable, so this command
wouldn't work.

Option 3 is correct. Using the tilde command in this context changes the current
directory to its previous value.

Option 4 is correct. In this circumstance, the tilde command changes the current
directory to the home directory of the user Fred.

Î 

C
 
 
   
      

5 6

- -’V 
8 - 
9 
/ ü

{
6

 |  




 
 
7 |  


 


@ |  
 


Ú |  2   



¦ 

{   
  

  
 
  [abc] 
a 


  

  [a-e] 
{ *  



2      ?
 
 


The command ? fi?- would use filename substitution to match and list files
named filea, fileb, and filec if they exist.

The command ?  - matches and lists every file named text with a suffix
consisting of a period followed by a character in the range of letters from a to e. In
other words, text.a, text.b, text.c, text.d, text.e will be listed.

The command ? fi?


will match and list any file with a filename that starts with
fi?, including fi? .

The command ? fi? will match and list any file with a filename that starts with
fi? and has one additional character, such as fi? or fi? if they exist.

A     

@
  
       



  

  


a 
  
    


× "< =
× "<'
 =

½V ÷
  "< =


  
  
    


  
 
*    



½ ÷
  "<'
 =


  

  
   
 

     


Î 

|  
  
    

   
 
      
 
 


? ?   MISSING CODE

¦ 

{ 
 
  
   

      ? ?

{     
          
  

$ ls ±l | grep $(whoami)
-rw-r--r-- 1 vincep vincep 9880 Feb 11 15:40 120415_log
-rw-r--r-- 1 vincep vincep 9372 Feb 11 15:41 120603_log
-rw-r--r-- 1 vincep vincep 73234 Jan 8 09:22 report1.txt
-rw-r--r-- 1 vincep vincep 247416 Jan 8 09:23 report2.txt
-rw-r--r-- 1 vincep vincep 451008 Jan 8 09:24 report3.txt

    



 

 
 
 

 

 
 

 
   



     


    



 

  

 






     
     3   



{     


       3 
 
 
  
   
  
  
        

$ echo '*'
*
$


 3 
 
backslash escaping   3  {    




 ½ 
 



{      

 

 
  
 
     

7

 
  
   
     



3 




 

{    

 
      
A*@* 




A

$ echo \'\*\' is a special character


'*' is a special character
$

Î 

  



 

 

    
   3        

 

 


    
 


4

5 6
- V  $|
8 V
$|
9 V
 $|

¦ 

a  

  





Option 1 is correct. The backslash prevents the $ from being interpreted as a special
character, so J SER will be printed onscreen, rather than the value of the J SER
variable.

Option 2 is incorrect. The J syntax allows you to pass the output from a
command as a parameter to another command.

Option 3 is incorrect. The J fi? syntax allows you to pass the contents of
a file as a parameter to a command.

X c       

#*

 *
 
  
 
 *
 

  
 

 
  a 
         
  


a      
   
 
    
   


 /usr/local/bin/ksh
 Logon welcome script
clear
echo Welcome $(whoami)

a 

 

    
  


 /usr/local/bin/ksh
 Logon welcome script
clear
echo Welcome $(whoami)
echo The current date is $(date "+%d-%M-%Y")

Î 

a 
  

  
    *      *
 
 *
 
@      

  *    


  ?V?’  
  ?V V 
V?
V %?V

V  V  
 &&&'
MISSING CODE

¦ 

a V ´ 

 
*         *



Î 

a  ? 
      *    

|  
       
   
  ? 
      
   A A


  ?V?’  
  ?V V 
V?
V %?V

V  V  
 &&&'
V ´
? ?   MISSING CODE

¦ 

a   
 

 
   A A

a    


  

Welcome vincep
The date is 26-08-2003
You have the following reports:
-rw-r--r--1 vincep vincep 73235 Jan 8 09:22 report1.txt
-rw-r--r--1 vincep vincep 247416 Jan 8 09:23 report2.txt

Î 

  


 
 
  
 

5 6

- @
  
      





 
 

8 @
  
      



  

  
  

9  

   
  
/  

    
  

¦ 

a 
        

 

 
 
  

    
     


Option 1 is incorrect. Redirecting standard output into the standard input of a


command is performed using the UNIX pipe facility.

Option 2 is correct. The command  I i J for instance, provides


the following output: I i Fri Aug    BST 

Option 3 is incorrect. The shell only performs filename substitution with wildcards.
The command  I i J
 will yield a "command not found" error
message.

Option 4 is correct. Filename substitution provides a quick way of searching large


directories for files conforming to a specific pattern.

 

: 
           

  

C    
 
 ½ 
3 
½  

  {    
 
  
   

   
 
 


| 
 
  
       




  
  
{     
 
 


   



a 

  
   
  

    
    

{     

){  )
)    )

)        )

)A      )

)X c       )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

c
     
¦ 

{

 
       

 

 

{ 
  

 
 
   
| 
     

         
  

          

 
  
        

     



a     


     

command1))command2

 
 
  
     





a   



 
     

command1++command2
 
 
  
     

  

     

a 
    
  
<?M=  

  {  
  

    
 
 

 
  

½ 

a 
    
   
  

  { 
     



     


 

  

a   
    
  
     
 *    
           
   
  noclobber   

 



a   
    
  
     
 *    
           
   
 even if noclobber   

 



a   
    
  
    * 
   
       
 

  
 

a   
    
  
 
$   



a   
    

      n



a   
    

      n

  

a   
   
 
      n     

  

a   
   
 
      n     
   
        
   

  

a   
   
 
      n     
   noclobber   

   

  

a   
   
 
   
        
{     
    
     
 

   

$    

a  @ 
 
 
  
 

a  4 
 
 
 


% &  %&  %X&

a 3

 
  




     
:   
     
   




a  N 


   

   
 
 {  
 

 *
  


    

½ 

a     
     



 
 
  



 

½  

a     
   
    
  





 

{   

a    
        
  $HOME




 

a    
   

       
  

  *    

a  >L 


        
    
     


a    
        
    
      

'    

  

  
   

 

    {    

  
   

a 


  
    
   
 

 {        
  
  
 
 * 


  


   
 
 


 
 

a 

 


  

 





  {   


  

   


 

|  

 
 
 
 
 

           

C   



 
     
   & <&5=
          

  { 
 
  
    
 

  

{     

 {   

 ¦  

   
       

       

    

 $    

 $     

      

 {    

 '     

   

  ( AUUX   ¦   


           
      c         
¦               

) )  ))

c  c
    
    

¦  


   
  
    
 
  

 




 

   *3   


  
   

   

    
  
 


    


       

 
   

{        


6

×    


×    
×     
   
  
{ ! c   

#*

 *  

 *  
       

   

a 
         


     

 
   
{ 
     
 

  
   
  4


MISSING CODE ? ?  
MISSING CODE MISSING CODE
?V?  
 ?  ?V?    
MISSING CODE
?V?   MISSING CODE
MISSING CODE V
  VV     V   

5 6

- Õ 
½½
8 |3

½%&
9 7
½

/ #



 ½

 

a 
½
  

  
      

Option 1 is incorrect. You use round brackets to perform command substitution, as in


the variable assignment command shown here:
DATE=J

Option 2 is incorrect. You use the square brackets to enclose conditional


expressions, such as:
if - JFEEDBACK = y 
 "pr"
? 
i
fi
Option 3 is correct. The syntax for a function ± a sequence of code that is available
to the shell into which it is read ± is:
fui { 

Option 4 is incorrect. The  special characters are used to perform redirection. They
are also used as conditional operators (less-than and greater-than) within conditional
expressions.

{ A! c    

   

| 
 
  ? 
 
  
 
   
  A A
 
 G
K

     


   
  


? ?   MISSING CODE MISSING CODE
?V?   ?  ?V?     MISSING CODE ?
V?   
MISSING CODE V
  VV     V   

 

a   -    ? 


  
 
    
 A A
 
 G
K

{ X! c       

   X

| 
 
       ? 
 
 


 

{   


 
  


? ?  - MISSING CODE ?V?  
 ?  ?V?     MISSING CODE ?V?   
MISSING CODE V
  VV     V   

 
a  

  ½     
 

 A  X

        


      

from 

  

{        


? ?  -  ?V?  
 ?  ?V?     MISSING CODE ?V?   
MISSING CODE V
  VV     V   

 

a  
  ½     
 

 X  X

a 
 
              

 

{   


   


? ?  -  ?V?  
 ?  ?V?      ?V?   
MISSING CODE V
  VV     V   

 

a      ½  



     

<   


 <


a *    


  
   

     
 
  
 

 

 
    
  
  

  
   


{ ls -l report[0-9]  localreports ;
mail -s "local reports" root < localreports ; }
|| echo
An error occurred during search operation
{     

){  )

)    )

) )

){ ! c   )

){ A! c     )

){ X! c       )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

"   c
 
    

¦  


   
 
 


 )     

Ë




  



#






           
 
 


H 






        
  
  

a 



   


       



 
    


| 
  
  

 




$ export DEST
$
#   


 
    

 




Ú

   

 
 

: 
 
 





  



 

{ 

 
   

: 
    


      



{  

    

6

×   
3  

  


×  
  
× 
 

  
 
×

 
3  



(
      
  




  

6

× 7  
× 7
  
× {@ 
× E  

    
{ 7    

 

  7  
 

  
{ 7
    
 

a 
  



 
 7
  
{  
{ {@    





{@ 



  
  

*  
#  {@  E     





E 
 


  
  


Î 

C
        

5 6

- 7
  
8 7 | 
9 E | 

{
6

 |  


 


7 |   






@ |  

 

¦ 

{ 7     



 7
    



  E     








The Bash shell is based on the Bourne shell. Although you can export variables to
make them global, they can only be declared locally.

The Bourne shell is the most universally deployed shell and, although it has a limited
feature set, it's useful for writing platform-independent shell scripts.

The Korn shell provides good support for variable typing and other useability
features. It's more likely to be deployed on proprietary UNIX systems than on open
source systems.

A c   

{   






  
 

       

a 

 

 


  3
 ½

 
  
  
/G1G 



 V

$ distance=4070
$

a 
   
 
 
 

   
 
   
     
   
 

$ typeset distance=4070
$

  * 



 


 

  
   
 


  



 
 V  
$ distance=
$

{   
 


!
 
  

 !   



  
 
 ½ 

{   
 


 
    

  



  
  

 
  
     
   V



$ print $distance
4070
$

a 

  
  

 
  


    
 

 
  
  
   V

 
  



 

$ temp=$distance
$

{  


     


 
     

{   
 
   
  
 

   

$ unset temp
$ print $temp
$

Î 


           4


  
   
    

5 6

- -1 /J
8 
9 

¦ 

{      -1 /J

Option 1 is correct. The value of the $departure variable is set to the value of the $t
variable. This variable is assigned a value of 17h45 in the first line of code.

Option 2 is incorrect. The command departure = $t assigns the value of the $t


variable to the $departure variable, not the character t.

Option 3 is incorrect. The command print $departure prints the value assigned to the
departure variable ± in this case the value of the $t variable set in the first line of
code. It does not interpret $departure as the literal string departure.

X Î  

 
       




 
£

 
     3 

: 
     

 
 
  




7
 

     3    
     
 
£



$ echo '***** Spain & Portugal *****'


***** Spain & Portugal *****
$

   3     




 
   


  


$ echo ***** Spain & Portugal *****


[1] 55412
ksh: Portugal: not found
$ add_pkg_files Spain

a 
      3     6

×  3 <=
×  3 ½
× 
3 ½

  ·  ½


| 3 <=   
  



{ 
   



!    

3 !


 

 
 

| 3 
  



  
   

    


  ·  ½
Ú 3 ½   
  




 


      
3 ½
  




{  





   

    
 3 {   
 3    


  

 
 ·  ½
7
3 ½

   
  
 7  { 
E  
    
       

    

 
3      
 

    a 

  
 




|
 
  



  V
  
 

 

  "JGa      3      

  


 " 






$ pricetag='$50'
$ print $pricetag
$50
$

#*

 
   
 
   
  V



    
  
 
  


  V? 

a   3  
 
   


  

$ pricetag='$50'
$ item='trombone'
$ priceline="The cost of a $item is $pricetag."
$ print $priceline
The cost of a trombone is $50.
$

|
   




 

         
   7
     
   ? 
 

 

 
3  

     ? 
  ? 


$ drlist=`ls -a scripts`
$ print $drlist
. .. add_pkg_files$

Î 

 


  
   "    





4

5 6

- Ë £ 


8 Ë  
9 Ë  
/ Ë  

¦ 

{ 

 
 3   "     







Option 1 is incorrect. Placed at the end of a command, the ampersand causes the
command to run as a background job, but it does not escape special characters.

Option 2 is correct. The backslash escapes all special characters, including itself. So
the expression ^^ will be interpreted by the shell as ^

Option 3 is incorrect. Double quotes prevent most special characters from being
interpreted, except ^ and 

Option 4 is correct. Single quotes prevent all special characters from being
interpreted, but they can't be nested.

Î 


           4


 ?  
©?    ?   
  ©? 

5 6

-  ?   
8 ©?   
9   
/  

¦ 

{        


  3 
 


  
  3    




Option 1 is incorrect. The special character $ symbol used to reference variables is


retained within double quotes, so in the command f?ig="Jir?i 77 " ,
Jir?i refers to the variable set in the previous command line.

Option 2 is incorrect. The print command prints the flightno variable, not the flightno
string.

Option 3 is correct. The first command assigns the value A to the airline variable.
The second command substitutes the variable at the start of a string that consists of
a space and the number 77 , and assigns the resulting string to the flightno variable,
which is then printed.

Option 4 is incorrect. Double quotes allow you to create variables that include spaces
because everything within the double quotes is interpreted as a single word by the
shell.

 

Ë




   

{ 
 



   



 

  


 |       



  

a 
 
 


 

  
     

a 
      
{ 
 
 



   


  
 
 ½ 

a 
3  
  

 


| 3 
 3 

     


  7
3 
   
  
 

 




{     

){  )

)    )

) )     )


)A c   )

)X Î  )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c
    
    

¦  


   
 

  


 +      





   
 


  
 
  


 
  


{  
  
 




 
 B 

  

 

 
 *B  

{ 
  
 


  

× ½=
× 
½=
×  


½ ?=
×   
B ½ =
×   
B   2 ½ ,=
×
  ½=

  ½
{  
 ½= 




  

{ 
  
    

    
  
  

  


 ½ 
{ 

 ½
= 





  
 

   
  
         

       
 : 
9-/-J
9-/-J  

   

   
  
      
 
 
: 
-KIJ/9
8-IG  
   
    ½  ?
{ 

 ½ =


  





 



*
  




{  

 ½=  





 


*
  
 



       ½  
{   B ½ =
B ½=
 
    


a  
 
         
 

Ë

   
   

          
 


   
  

        
        - ½ , 
{   B   2 ½ , =
   B  


 
   
  
  
     
 2 

{ B   2 ½,=
 B  


 
     

 

 2 
  ½
{ 
  ½=
 
    



   
 
{    
 
 
 


     

a    


 

 



 
 
  ½ 

 

 ½  

 
    
 < =   



$ typeset -i dist
$

 
    
    



$ typeset +i dist
$
a 
  
 
 
  
   


 < =
 
  
 <=  



$ typeset -ux name


$

Î 



    

  


4

5 6

-  
 

  
8  *  
9 7  
 

  
/   
 

  

¦ 

a 

  


     

  
å   
*
  






{ 
 

 


 



 
     


  
   


 
    
 ½=   



  
 
/0K

$ typeset -i dist=489
$

 
   


* 


: 
  
  

  

 < = 
 
 5ËE

$ name=Novak
$ typeset -u name
$ print $name
NOVAK
$

a 
 
 
 ½=  
 
  
 

  




   
  
  
 
  


   * 


a 
   
  

  
 


 



 

 

: 
 
 

  


    
 ½=

$ typeset -i
MAILCHECK=600
OPTIND=1
PPID=55394
RANDOM=22348
SECONDS=700
TMOUT=0
dist=489
$

Î 

C
  


     

5 6

-    
8    ?
9    
/    

{
6

 (
 

 

 



7 (
 

    
@ (
 

 B  
Ú Ú  



    
 

¦ 

{  
  




  
    ?

 
 


 

 
 

 

 B  

The Ñi attribute is useful when you are using variables in calculations. It enables you
to make sure that numbers are assigned to the variables, rather than letters.
The Ñ? attribute is useful if you need to format the case of a variable consistently,
irrespective of its value.

The Ñ attribute strips any leading spaces from a variable, which is useful when you
want to avoid errors in shell scripts in which variables are set interactively by the
user.

If you want to make a variable available to subshells, you must export it using the Ñ
attribute. However if you want the variable to be available between logins, or to other
users, you will need to add it to a shell configuration file.

A "   




 


  { 
      

      
  
 
   

(   





    *
{ 
 



 
 
*   

 


* 


    


 
 
  
å  

 
    




(
    




×  | 

  
*
 
×   

  
*    
×   

   
 
  


{  
 




    
    
  

× ü
× 
× 
× 
× (
× 

ü
{ ü

 
  
  


  
 
 
    
 G  *   
 
  2 

{ 

 
    

     

{  

 
  Ú< Ú=  

 
  
 
  
 

{  

 
  Ú< Ú=     
(
{ (

 
  Ú< Ú=    *
 
 

{ 

 
      
 



{ 

    
 


 
 

Î 


    
   
 


 
ü
 

5 6

- Õ
   
8 |  
9   
/ Ë   

¦ 

a 
  
 


 
*
   
     

  


 

 


 

   
  { 
    
  3  
  

  





        
   




 
 
  
      
 



  
  
 

 
  
 
 


 
 
 
 

 ?  
 

  

 
 

       
 
$ ls -a /usr/home

  




 
   

{ 
 
  
       
   
 
 
     

 

  
   
 
 



   
   
    


 { 
  
         
 


disf() {
> ls -al | grep $1
> cat $1 | more
> }
$

a 

   


    
      



           


 

½


: 
     


  

{    
 
    








{          




Î 

  


 
    




5 6

-   



  
  
   
   



8   


8 
  
  
 


9   


G

 
 
 

 
 

  
/ a 
   


  
   
 
 
 

¦ 

  


G  
     

8
   
 
  
5  
 
   


  
 
  
        
Option 1 is incorrect. You can view positional parameter 10 or greater, but you must
enclose it in braces, as in J{ 

Option 2 is correct. For the command  fi? fi? , the value of J is fi? .

Option 3 is correct. For the command  fi? fi? , the value of J is .

Option 4 is correct. You can access an argument to the pi? function as


shown here:
pi?  { J  ? 

 

a 

 

 


 
   
  
 


! 
   

  
  

 { 

    
   




! 

  
  


 B  






  

{      

 
 

        


 
   




   
   


 
    
  
 

{     

){  )

)    )

) +      )

)A "   )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

)        c


  
    
¦  


    

  
  

 

 )   

Ë


 
   
 
 

{     



       
 


  {    


 
 ½    





5    
 
   
     


*
 
    


*
   
 

 




a 

½
   
 


 


    



{ 
    


 
  
 


 
  



 
 

 
 
A(

A 
 


 
 A(

{
A       



$ en=EasyNomad
$ en=${en}Travel
$ print $en
EasyNomadTravel
$

  





  

  ½ 
     

!   

  


 
    
  
 
  



-J



$ print ${en}
15
$

{    


  

      



 

6

× "?
 6M
× "?
 6OM
× "?
 6LM
× "?
 64M
× "?
 64M


º! 
{ "?
 6M
 
  

  *
  * 
   *     

: 
 )  ©  
  


    
  
A
  A

º! 
{ "?
 6OM
 
  

  *
  *
    *   
     



  

*


: 
 )   
  

 
  
  
A
  A 
 
A
  A

º! 
{ "?
 6LM
    

 
 
*    *     

: 
 ) ?     A



 A  
  

 
      
 


º! 
{ "?
 64M
 
  

  *
  *
    *     
  
 


a 
  
 




 
   
 

º!
{ "?
 64M
 
  

  *
 5  
   
  
A

  A
  
 


{    


  

   
  



6

× "?
 6M
× "?
 66   M
× "?
  M
× "?
  M
× "?
 M M
× "?
 MM M


º!
{ "?
 6M

  
 


  


           


: 
  
  

 (

   ) 
A
A

º!!÷
{ "?
 66   M

  
 


{  
  
 

       
 






     

: 
  
  

 (

   ) ) 
A A

º ÷
{ "?
  M
    

    

   

*
    
 
 
 


: 

 
   

 A
    
A{ 
   ?   
  
  
@
  
  A    
A

º ÷
{ "?
  M
    

    

   



*
    
 
 
 


: 
  
   

 A
    
A  
 ?   
  
  
@     
  
  

º ÷
{ "?
 M M
    

    

     



*
    
 

 


: 
  
   

 A
    
A  
 &?  

  
  
@
    
A
    A

º ÷
{ "?
 ## M
    

    

     



*
    
 

 


: 
  
   

 A
    
A  
 &&?  

  
  
@     
Õ     

{    


  

    

  



6

× "?
 & $& %M
× "?
 && $& %M
× "?
  $& %M
× "?
 M $& %M


º ÷ ÷
"?
 & $& %M
   
   $ 


*
  
 %
 

: 

 

  
  A#
   
 
   A 
    ©?    
A#
  
    A

º ÷ ÷
{ "?
 && $& %M


 
   $ 


*

   %
 

: 
  

  
  A#
   
  
  A    ©?    A#
  

   A



º ÷ ÷
{ "?
  $& %M

   
   $ 


*

   %  
    $

: 

 

V?  
  A@    A 
 
  V?   V  A     A

º ÷ ÷
{ "?
  $& %M

 
 
   $ 


*

   %  
   $

: 
  

V?  
  A@    A  
V? &©? V   A@    A

Î 

a 
 
  © ?

 © ? 
|  
 
    


    



5 6

- { 
 © ?
 
  

  -8
8 { 
V © ?  J
9 { 
V © ?)   -
/ { 
V © ?)ü


   

¦ 

Ë


 
     
 


 

  

   

 



B

 




Option 1 is correct. You can expand the current value of a variable and include it as
part of a new string, or perform an arithmetic operation on it if it is an integer to
create a new value.

Option 2 is correct. When using braces to expand a variable, preceding the variable
name with a # symbol returns the number of characters in a variable, not the string or
integer itself.

Option 3 is correct. The number in this syntax identifies where the returned string
starts. In this case the variable has been assigned a five-character string, so only the
last character is returned.

Option 4 is incorrect. This only happens if the fi? variable has either not been
assigned, or has been assigned a null value.

Î 


    
  


  
4

5 6

- Ú 

    
 


  
8 (

   
 



9 Õ

   
 


  
   
/ Õ
 
  

   
 
  



¦ 

 


  
 
 

    
 



  

   
 






   
 


  
   
Option 1 is correct. If the fi? variable is not set, or has a null value, this command
will output the message "File not found":
 J{fi?Fi?  fu

Option 2 is correct. If the fi? variable has been assigned the value fi? , you can
return just the using the command:
 J{fi?

Option 3 is correct. If the fi? variable has been assigned the value fi? , you can
replace the 2 with a using the command:
 J{fi?  

Option 4 is incorrect. Variable expansion isn't used for this. You simply assign the
variable as shown:
r=Jfi?

A ¦







 
  
 

3   

{ 
 




   

a  
  
  



 
  
         3     


{   
    
    3



   
2 {          ,G.    
    ,-.
  

Î 

å      







4

5 6

- 7
  


  
  


8 7
  

     
9 7
  

  


/ 7 
 
  


   
  


 


¦ 

a  






  

     








  
       





  
  

*  

 
  
  
AP

A  

 
 
 
A:
A  -   
  


{ 
 
-   AP

A

$ mth=January
$ mth[1]=February
$ print ${mth[0]}
January
$

 
     

     


   


   


   



 
  
 

  /LK    

  
    
{     
       

 

V  
 
 V  9
      


 A  
A    A  
A

$ items[4+9]="safari hat"
$ print ${items[$count]}
wooden giraffe
$

{    


  

      



6

× "?,@.M
× "?N,@.M
× "?N,@.6 M
× "?N,@.6 6M
× "?,@.M
× "?, .M


%&
"?,@.M 
  




%&
"?N,@.M 
  
 2  
 




%&!÷
{ "?N

,@.6M
 


        

: 
  - ) 
     

    
  


%&!÷!
{ "?N

,@.66M
 

        

: 
  - ))       
      
 



%&
{ "?,@.M
     




%÷&
{ "?, .M
    

      , .

#*

 
  
  


  


 

 

   

  
      
 

{   

 
  


     


a   
    

$ get_item() {
>

a           


 a    
   





$ get_item() {
> print "Item no. $1"

{            


 






  


$ get_item() {
> print "Item no. $1"
> print "Length ${items[$1]}"

: 
   
     

$ get_item() {
> print "Item no. $1"
> print "Length ${items[$1]}"
> print ${items[$1]}
> }
$

  
      8 

      
 

 


$ get_item() {
> print "Item no. "$1+1
> print "Length "${items[$1]}
> print ${items[$1]}
> }
$ get_item 2
Item no. 2
Length 14
leopard poster
$

Î 

 3  



  




C
  
 
    

      
  

5 6

- "?
,@.M
8 "?N
,@.M
9 "?
,@.M

{
6

 Õ
    


7 Õ
   
 2  
  


@ Õ      



¦ 

{ 
  - 
    

 - 
   
   
  -     





The * metacharacter is used as a wildcard. You use it to reference every element in


an array.

You use the ! metacharacter to reference the subscript values in an array. A


subscript consisting of a number equal to the total number of elements in the array is
initialized whenever you add an element. You use an element's subscript to
reference the element.

The value returned when you use the # metacharacter will be equivalent to the value
of the last subscript to be initialized for the array.
 

{   


 
       
 

 



  
 

 

 


*
a 


  



 


a 
   
 


    


a 
 


   


 
   3



{     

){  )

)    )

) )    )

)A ¦)

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c
      
    

¦  


   
 

  


     

a 
   

  

 
  
 
 

   {  

  
    
    

å            

{  

 

 
 
 
 
  : 

   (  
  

 (

å   

  

 

     
 


    {      


$ integer itemID=5


  
 


     
    
    
    

$ typeset -i itemID=5



    *  
-G
 
  
   

{  

   
-G 
 

 

   ½
 

 
 
  
   

--G- 
  ’’?



$ nibble=21101

a 
 

 
        
 

  
   


 7-:1     



$ typeset -i16 position=B1F7



You can use any base between 2 and 36.


     

 

 { 

  

     -

$ i = `expr $i + 1`

C       ?




{ ?
 *3 
 
 
 ½    



*
{ 
   


  
  IG
 

  


$ let i=i+1

   
 


 

  
   
    3 

$ let "i=i + 1"





    ?
 

  
 


  {  
    



  

 


 

$ ((i=i + 1))

   





  
        
  
   
  
 
 

C 
 ½
  ½ 
 
   
  ½

 
½ 
  
      

Î 


     
      4
-8@</0&IL8=

5 6

- 9I
8 18
9 -8G
/ -//

¦ 

{  -8@</0&IL8=

 -8G

{   


   
 ½  


       
  

: 


"&" 

 8
-0 0 8



8

$ ((rem = 18 % 8))
$ print $rem
4
$

a 

 
 
 



  ½ 
  
 


å        
  

 


     
     







 
$ let "num = -9"
$ print - $num
-9
$

Î 

  


     
  



5 6

- a 
 
 

*
-G
8 a 
 
 
 
9 a       

 


/ a    
 



¦ 

a 
      
 



*

-G 


 
  
  

8

Option 1 is correct. Integer variables can use any base between 2 and 36, although
the default is 10. You can declare hexadecimal integers like this:
Ëri?= 

Option 2 is correct. Binary numbers are base 2, and you can use variables with base
2 integers as values.

Option 3 is correct. To explicitly declare an integer variable, you use the yp  Ñ
i option.

Option 4 is incorrect. You can make a variable an integer variable by simply


assigning it an integer value.

A      

{    


 
 
  7 
   
  
 

{  
 
 
   


×  
Ú½
×  
5Õ½
×  

 ½
 ¦
+ ½
{ ££ 
  
   


  
 

 2    

 2 

     

 

     

  
  ½
{  
  
   



    
2       


{   

       


  ½
{   
 


 
    



 

 2    
 
   
  


{    


   
 

 
 
 
  


 
     
 
  7 
     
 

{         
 

{    


 


×   Ú½
×   5Õ½
×   5Õ½
×   
 ½ 

 ¦
+ ½
{ £ 
  
       
- 
-

G       G

: 


  £   

 8-GG-
  ½
{  
  
          - 
-

G     
G

: 


     

 8--G-
  ½
{ € 
  
         
-
    

G 
-
G    
-     
G

: 


  €   

 8-GG
  ½ 
{ ´ 
 
    
2    
  


: 


´   

 8--G

{      


 { 
  
 
  
            
    


{   


 ½    

: 


   

 8-GG-G


   

 
8--GG

{  
     
2 

{     


 ½      

: 


   

 8-GG7 
        



 

Î 

  
        
 
  
 

 4

5 6

- >
8 +
9 Q
/ )

¦ 

{ > 
     
   
 
  
 

 

Option 1 is correct. If you perform bitwise negation on the base2 integer 10001, the
result will be 1110.
Option 2 is incorrect. You use the & symbol to perform a bitwise AND on two binary
expressions.

Option 3 is incorrect. You use the ^ symbol to perform a bitwise XOR on two binary
expressions.

Option 4 is incorrect. You use the | symbol to perform a bitwise OR on two binary
expressions.

Î 


               4
<<O8--G-+8--G==
<<O>==
 "

5 6

- G-GG
8 --
9 G
/ -GG

¦ 

{      8-G--{  


  8G-GG
 
 
     
   


Option 1 is incorrect. This is not valid output for a binary integer. If it were, the
leading zero would be stripped.

Option 2 is correct. The first statement compares the two binary numbers, bit by bit.
Where both bits are set, the returned bit is also set. Where one bit isn't, the returned
bit is also not set. The second statement performs bitwise negation, unsetting set bits
and setting unset bits.

Option 3 is incorrect. This would be the result if the first statement were a bitwise OR,
yielding a result of 1111.

Option 4 is incorrect. This would be the result if the first statement were a bitwise
XOR, yielding a result of 1011.

X ¦  
{   

  

  
 
 
 
  
 { 
          

 

{  

  
 
   


× 
½
× 

½
× 
 3
 ½
× 

 3
 ½
× 3
 ½
×  3
 ½

   ½
{  
 G<=     

 
 

 
 
   
-<
=
   ½
{  
 G<=     

 
  


  
 5   
-<
=
    ·   ½
{   
 -<
=     

 
  


  
 5   
G<=
    ·   ½
{   
 -<
=     

 
 


  
 5   
G<=
·   ½
{   
 G<=     

  



  
 5   
-<
=
 ·   ½
{   
 -<
=     

  



  
 5   
G<=

5    


   
           





{      
     
   
 

{     
 ½


 


*3
   


   
  
 

: 


V      V 



-
Î 


               4

  "
 ü

  
V 

5 6

- /-K
8 8
9 9

¦ 

{      9

Option 1 is incorrect. The first line does not return a value of 417. The first line
evaluates a conditional expression and returns a value of 0 or 1, depending upon
whether the expression evaluates as true or false, respectively.

Option 2 is incorrect. When a conditional expression evaluates as false, a value of 1


is returned. So the value of J that is incremented by 2 is 1, and when J is printed it
has a value of 3.

Option 3 is correct. The J variable is assigned the exit status of the previous
command. In this case, the previous command is the conditional expression that
evaluates as false, so the value that is assigned to J is 1. The next expression
increments the value of J by 2, and the print statement prints the new value of J ±
3 ± to the screen.

{    


 ½


 


*3
   


   
  
 

: 


      



-

Î 

a 
     
 
 
 

6
   

 
    
   
4

5 6
- "%O"
8 "'"LO/
9 "OO"
/ "NO"

¦ 

"'"LO/"%O"
"NO"
 

 
    
 
    
 
 

Option 1 is correct. The >= operator means that the value on the left is equal to or
greater than the value on the right of the operator.

Option 2 is correct. The +=4 operator increments the y variable by 4, making it larger
than the x variable, so the statement is correct.

Option 3 is incorrect. The x variable is greater than variable y. The == operators


means "is equal to", so this statement would result in an error.

Option 4 is correct. The != operator means "is not equal to", so this statement is
correct.

 

a 



  
   ?
  

*   
{ 
 
  
 
   
  
   
   

  
 {       
   !    
 

  
    
  

 !
    
  

{    

   
 
  7 
    
     
   
 

{  
   

  
 
 
 
  
 

{     

){  )

)    )

)     )

)A      )


)X ¦  )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c       c



    

¦  

 
&   
  
 


  


 

   *3   


    
  
 
  




{        


6

× 
 

  


×   
  

 
 

#*

 *    (


 

 *3   

  

 
 
   


 


 
 

{ ! ¦    

:       




      



  

  

   
  

   A

{    
  

    

{ 

 


 
 
 
  



 
 

  ?V?’  
MISSING CODE
 

{     
 
 

 

 A  A

#*


  
   -G 

@     


 




V

  

 -G  

  ?V?’  
    MISSING CODE

 

a V   

 



a 
 

  
  

a  *
 

 
 
   
 


 /usr/local/bin/ksh
typeset -i commrate=10
typeset -i amount

{ A!     

{    
   
 
 
 






 
 

   X

{ 




  
 

  ?V?’  
    V 
     
MISSING CODE

 

{ ?



  
 

 A  X
{  

  
    * 
    




  ?V?’  
    V 
     
? MISSING CODE

 

a    
  
    * 
    




 X  X

{ 
  
 

     
  

   



  ?V?’  
    V 
     
?  
?   MISSING CODE

 

a  V  


    
  

  



a 

  
    
   

{     


 /usr/local/bin/ksh
typeset -i commrate=10
typeset -i amount
let amount=$1
let amount=amount*commrate/100
print amount

{     

){  )

)    )

) )
){ ! ¦    )

){ A!     )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  )

c
 
¦ 

{

 
 
   
 

 

     


  


 
      

 5  
  

 
     

  
 
 

   

5     
  
   



  

   {+{&7{ @ 
  
-KIG

{   
   
   
 3 


 
  
 
  
 (

 
     

  
 
 
  
 {    


 
  !
AA!
    
 




  @
   
 
  
 

{  

{    

    
 
    !
   
 


 
  
 { 

    

 
 



 
 
    
    
  { 
  

  


  
    a 
  
  
 |   
 < =
  < =
    
  




   
5  
 
|@Õ { 7C

|  Ú  
|

Õ 
<Ú|Õ=
{

   

{   {

{ 
  
    

 

      

 
  
  

  
  
 


{  
  2

 
 

3
 

 




 



 

: 
 
 H  

       
 



      



#
{ 
 
 
 {
 

 
    

   

  

   
  
 

 



{ (
  
     


#    
(
  

#    @{    




     2
(


(
 
 
   
  


  
     
{ 
   

           

 a 


   
   

 
(
    
  

a 


    (
 
   
 
   (
  a 
 
!     

!
     (


    
 

    


      
(

{ 

   

 
  
     
{    



×    
×  



×   (Õ#




{    

  

   
  

  

 { 
     A
A        

  
    



a 
 

 
   


  




  
  

 

    


 
      


 6

sed -e '/^line.*one/s/line/LINE/' -e '/line/d' easynomad.txt





    
   
E 

 
 


 
  


   

 

   
 
  
  
     
å      



    
     
 
 (Õ#



a 


  
 

      

 


  
 

 

    


 

      
  

 
  

awk {$2="";print} profile

 

(Õ#< 

(
 
Õ #

= 
 
 
 

 
  
  
 
@ 


  
    

 @ 
 (Õ#
   



    

(Õ#
     




  



   

3
   

 

 

Ú    


  
  B   {+{&7{ @ 


      7
 
   

 
 

   
3      

   
   
C        
{!      
   !
(
!    
!     
   

{       




 (Õ#
 
    

 
  
     
 


 
 
 (Õ# 
 
 
 
  

{     

){  )

)¦ )

) )

)   )

){  )

){   { )

))

)    )

) )

@   F8GG9| |  #@   


| | 
 | |   


  


| |  #@   |

 
    
     


        

) )  ))

c
   
    

¦  


    
  



    

   



   

         

  
        

 

 
 



 

 
   



     *

   
 

   


  

 

  
  




  
   
  


a     
 

 
       
 å   

   
 
  

a 
  
         å   

  
            

|
 
  
     
 
    
3  

 



    
    

Î 

7
     
 ! 
 !   


 
 
 

 


    
 4

5 6

- @    


 
 
 
8 @   Ú5|   
9 Ú 
  
 

   
 
/      
    
J |    
  
 

¦ 

a 
    
 
 
   Ú5|  
 a 

  
  
 


  
 
      
    

a 
  
 

×   ©

× 
 
  
 

    © 
a 
 

   
    
  
 



      ©  

: 
    ©  ?  
   

 
 

 
 
  
       
 
   
    ’   © 
    
       


å     V
        
 
 

Î 

a 
    
 
 
 

  
   
 
     
  4

5 6

- V        


8  ©      
9  ©      
/      

¦ 

a   ©              

  

Option 1 is incorrect. It is possible to pipe input into sed, but to do so, you would use
the following command:
 rpr    Ñf i 

Option 2 is correct. You use the Ñf option to specify the file containing the 
commands, and then you provide one or more files for sed to operate on.

Option 3 is incorrect. The file containing the sed commands is provided after the Ñf
option, and not after the file on which sed is to operate on.

Option 4 is incorrect. This command would work if edits.sed were an executable file,
but in this example it just contains  commands.
A '      

{  
 
 
     
     
  

 
        6

×   

× 
 

 
× 
 

:  
      €    A  A    
A
A      
    
 




The sed utility supports most of the regular expressions that other UNIX text utilities (
such as awk, gawk, and grep ( and UNIX shells support.

{   
     



× €
× 
× 
× ü
× - 

€
{ € 
  
 

       
  

   
^

   
      
 

:  
  
   €       { 
  { 
  {  
    
 

{   
  
 

     
  
   

:  
  
       





< 

 

 <
 
  
 

{  
  
 
   
  

  


    
   

:  
  
   -    

  
 
ü
{ ü 
  
   
  
  

    

   

:  
  
   ü        
 
 Ú    /
-
{ -  
  
     3

  
  

 

:  
  
   -  -    
  

 
 
   AA
AA    
A(

A

Î 

|
     
  
 

|  

 
 
        

5 6

-        
8   - -€    
9   €    

{
6

 Ú

 
 
 
7 : 

    
 
   


 
  
@ Ú 
  
 

¦ 

{ 
        

 
 
 
  - -€     
  
 
 
 €  ’? ?     

    
 

   


   

The  option to sed substitutes anything matched by the first expression with the
contents of the second expression. In this case, the metacharacter
matches the
preceding character ± a space ± zero or more times. The J matches the end of a
line. Because nothing is specified in the second expression, the effect is to delete all
trailing spaces from each line.

The  option to sed substitutes anything matched by the first expression with the
contents of the second expression. The expression - -
J matches any string
that starts with a space, but which contains anything other than a space thereafter,
and is at the end of a line. The effect of this is to match every word at the end of a
line.

When it is not preceding a class or range, the circumflex  matches the start of a
line or string. In this example, J matches the start and end of an empty line. To
insert a paragraph separator such as --- you would adapt the expression as follows:
 '  J'  


     
< = 
  < =
<=

<=
    


:  
  
     
  
 



a 

 
            

      


:  
           A  A  8 
  
 

     A  A

 
           

 
 A@   (

8GG9A
 K 
   

 
     K    
  
      

a 
 

  
!
 ½ =
 ½=! 


       
   

{ 

   
  
 
  
 
  


      
      

7
 
        


 3 
 
<  =
 
       




The UNIX man pages provide a full listing of the sed options, with examples of their
usage.
Î 

  


 
  


5 6

- a 
     

  

8 a  
 
 
9 a   
   
/ a       

¦ 

{ 

    
    
 
a 
 
         
   



Option 1 is correct. You can precede your  command with the number of the line
on which it is to operate.

Option 2 is correct. You use the  command to append text in sed. For example, this
command adds the text "ir " to the end of line 10:
 ^ir 

Option 3 is correct. You use the i command to insert text in sed. For example, this
command adds the text "ir " to the start of line 10:
 i^ir 

Option 4 is incorrect. You use the Ñ option to suppress printing of all output except
that explicitly matched by the  command.

Î 

C
   
 

       

5 6

- €
8 
9 
/ - 

{
6

 C
 
 
 


7 C
 
     


@ C
     
 
Ú C
   
 

¦ 

a 
  
 
   €
  
    a -  

 
 
 


@ 
    

2   
 

The command matches the beginning of a line. In this example, the  command
will delete any new line that starts with a space:
 ' '

You match the end of a line with the J command. For example, this command
changes DOS newlines to the UNIX format:
 '  J'

The V command matches the preceding character, zero or more times. The following
 command will replace the character A with :
 ' 
 g'

The - command matches a class of characters. For example, the following 


command will delete any line that starts with a number:
 ' - 
'

X     

#*

 

   
  


   



| 
  
 
  -GG  <-GG= 
 
    
 

       
 

{        

{   
    
  A-GGA 
 


bash -2.05a$ sed 's/100-/(100) /' phonelist.txt


Name Home_Number Cell_Number E-Mail
Greg (100) 100-555-1111 100-555-1112 GregL@easynomad.com
Tanya (100) 555-2222 100-555-1113 TanyaS@easynomad.com
Sam 101-555-1111 101-555-2222 SamO@easynomad.com
Daniel (100)555-3333 101-555-1114 DanielB@easynomad.com
Nick (100)555-4444 101-555-1115 NicholasN@easynomad.com
bash -2.05a$

{ 

 
  A-GGA 
     

:  
   H
{

*  
    A<-GG=A

bash -2.05a$ sed 's/100-/(100) /g' phonelist.txt


Name Home_Number Cell_Number E-Mail
Greg (100) 100-555-1111 (100) 555-1112 GregL@easynomad.com
Tanya (100) 555-2222 (100) 555-1113 TanyaS@easynomad.com
Sam 101-555-1111 101-555-2222 SamO@easynomad.com
Daniel (100) 555-3333 101-555-1114 DanielB@easynomad.com
Nick (100) 555-4444 101-555-1115 NicholasN@easynomad.com
bash -2.05a$



Even though you've used (substitution) options on the phone list file, its original
content doesn't change. The command to change "100-" to "(100)" , for instance,
changes only the data output and not the original text.

#*

 
 
  A8888A  AJJJJA
      
  
  


      {


|
* 
 
   


  A8888A

bash -2.05a$ sed 's/2222/5555/p' phonelist.txt


Name Home_Number Cell_Number E-Mail
Tanya 100-555-5555 100-555-1113 TanyaS@easynomad.com
Sam 101-555-1111 101-555-5555 SamO@easynomad.com
bash -2.05a$

{ 
    
 <=    

   
 !  
    < 
 

bash -2.05a$ sed 's/4,$d/' phonelist.txt


Name Home_Number Cell_Number E-Mail
Greg 100-100-555-1111 100-555-1112 GregL@easynomad.com
Tanya 100-555-2222 100-555-1113 TanyaS@easynomad.com
bash -2.05a$

a 
 ·<3 =    
  
   
   ! J
 

bash -2.05a$ sed '5q' phonelist.txt
Name Home_Number Cell_Number E-Mail
Greg 100-100-555-1111 100-555-1112 GregL@easynomad.com
Tanya 100-555-2222 100-555-1113 TanyaS@easynomad.com
Daniel 100-555-3333 101-555-1114 DanielB@easynomad.com
Nick 100-555-4444 101-555-1115 NicholasN@easynomad.com
bash -2.05a$

#*

 
  
      |
* 

{     <=      
 

     
  A|
A    

bash -2.05a$ sed 's/^Sam/d' phonelist.txt


Name Home_Number Cell_Number E-Mail
Greg 100-100-555-1111 100- 555-1112 GregL@easynomad.com
Tanya 100-555-2222 100-555-1113 TanyaS@easynomad.com
Daniel 100- 555-3333 101-555-1114 DanielB@easynomad.com
Nick 100-555-4444 101-555-1115 NicholasN@easynomad.com
bash -2.05a$

a 
     
 
 
 

 
  

9     
8   

  

 
 

bash -2.05a$ sed 's/555/55/g' > newphone.txt


Name Home_Number Cell_Number E-Mail
Greg 100-100-55-1111 100-55-1112 GregL@easynomad.com
Tanya 100-55-2222 100-55-1113 TanyaS@easynomad.com
Sam 101-55-1111 101-55-2222 SamO@easynomad.com
Daniel 100-55-3333 101-55-1114 DanielB@easynomad.com
Nick 100-55-4444 101-55-1115 NicholasN@easynomad.com
bash -2.05a$

 
  
   
  
  *
 
 
 
  
 
 

  

 
    

   <  =


cat sedscript
s/555/55/g
s/100-/(100) /g
s/101-/(101) /g
s/easynomad/EasyNomad/g
  
   

       
  
 
        

bash -2.05a$ sed -f sedscript phonelist.txt


Name Home_Number Cell_Number E-Mail
Greg (100) 55-1111 (100) 55-1112 GregL@EasyNomad.com
Tanya (100) 55-2222 (100) 55-1113 TanyaS@ EasyNomad.com
Sam 101-55-1111 (101) 55-2222 SamO@ EasyNomad.com
Daniel (100) 55-3333 (101) 55-1114 DanielB@ EasyNomad.com
Nick (100) 55-4444 (101) 55-1115 NicholasN@ EasyNomad.com
bash -2.05a$

 

| 
  
         

 

 

 


 

{  
 
 
     
     
  

  
 
 
 
 



    

|
     

   
   
    

     
       
  

{     

){  )

)    )

)    )

)A '      )

)X     )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

      


    

¦  


   
  





 

   *3   



  
  
  

  

{        


6

×     


×   
 

{ !      

#*

 
 

   
  
A A  

H#((|5     
   
     
 

a    
 

 

 
  


 
AD A

   A

#*

 
 

 
  A-KGA A-K8A

|  
 sed

   -KG 


sed MISSING CODE

 

a *&-KG&-K8&*    


  
 

 
 
A-KGA A-K8A

 A  A

#*

 
  

  
   
  



@   
     
   
D 

   

     (||( 

5 6

- D % 


8 %D 
9 D ' 

 

{  
   
   
D 
    
hosts > en_hosts

Option 1 is incorrect. This option uses en_hosts as the input file and hosts as the
output file.

Option 2 is correct. The data on the left of the > redirector is written to the file on the
right of the redirector.

Option 3 is incorrect. This command would redirect the hosts file as an argument to
the command on the left of the redirector. Since en_hosts is a file, this command will
generate an error.

{ A!        

   A

#*

  

 
  A A A D
 A 
 D   
  

@   
    
  

 
A A


 (||( 

5 6

- *&Q & D


 &*
8 *& D
 & &*
9 *& & D
 &*
/ *& & D
 &*

 
a *& & D
 &*     
 



  A A A D
 A  D   
  

Option 1 is incorrect. This would only replace the string "gleeson" if it appeared at the
start of a line.

Option 2 is incorrect. This would replace gleeson_assoc with gleeson, instead of vice
versa.

Option 3 is incorrect. The g flag is required to ensure the each instance is replaced,
not just the first. The p flag sends the results of each replacement to standard output.

Option 4 is correct. You use the command with the a flag to perform global
substitutions. The first term is the search term that is replaced with the second term.

 A  A

|  
  
     
 
 
   


  ? ?  V (||( 

 

a D     


    
  

{     

){  )

)    )

) )

){ !      )

){ A!        )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

     c



    

¦  


    
 

    

#     




 
 
 å   
  

 
   

 



 



   


     

  

  
   


 


 
  




Awk derives its name from the surnames of its developers, Aho, Weinberger, and
Kernighan.

Î 

  
   
   
 


   
  
 

       


    

      

 4

5 6

- Ë  
 


  
 
8  

 
 
 
  

 




9 H
  
 
/   
 

 
 

¦ 


     

  
 

 

 
 
  

 





 
 

{  
   

×   


×  
 
   

     
{  

  



   

a 
  


      


   


   


a 

  

   
   
 
  

     
{ 
       

   

a 
  
  

 
   
  
  
 
 


     


 
   
      

     
6

×  

×  
× : 
×  
O 

   
a 
      
 
 
      
  

 
   {  


    3     
 
 
  
V
a 
  
  !  
 
 
  


!  
 {  


         

 
 
 

    
    
        
 3       
  
$ VV
a  :      

    

 



 
 
 


:  
    

 
  

 
   )
 º

a   
O      
 2


  
 {  
  

    

Î 
  
 
      


5 6

-   


 
 

 

8 a 
  
  
  
 
9 a 
  
 2

  

 
/ a  ©    
  
 
 
 

¦ 

 
 
  
   
 ©
  
  
 a 
  
 2


  

 

Option 1 is incorrect. You can specify multiple files for an awk program to use as
input.

Option 2 is correct. You can specify the patterns to be matched and the actions to be
taken as a single awk command line statement.

Option 3 is correct. You can use the Ñ option on the awk command line to name a
variable used in your awk code and assign it an initial value.

Option 4 is correct. If you have a complex awk program that you want to reuse, you
can store the program instructions in a text file to read in from the awk command line.

A ¦   

 
 
  
  

 
  

 
  

  
 
 


 {  

  
   
 



, 
Ovalue.,:field separator.,.'pattern?actionM*
Ovalue datafile(s)

a    
 

    
½
 


 

     




  


 

 ½ 


 
 
 
   

  
      

{     
  

 

 
  


  
 
 
 3
½ :  
   
      

  
   J 
 
       

   
  

 

  
 

 
  


½
½

 3
 ½

 

  


 
        
 
5Õ½
 
Ú½ 
 

{ (
 
    
 ! 
 

  
 
  
   !
   

    

{ 
 
    
 ! 
  
   

 
   
 

 
      
!
  



  
  

{ (
  
    




 

{ 
  





 
 

    
 
      



   
   
 

a  *  




    Õ
  
 



   *

:  
      A(

A  

bash-2.05a$
bash: / : is a directory
bash-2.05a
for i in terry larry mary
do
mail $i << END
$(date)
Have a good holiday $i
END

quit
exit
clear

{
en='EasyNomad'
print en;
}
   


a 

   

! 

 
 

 
    


! 

  !




{     







×   
×   "-" 

× |
|
× |
|

  
{ 

        
   
      

 


     ÷  
7   


 "-" 
         
|   |
{ |
|

   

 
   

 
  
|   |
{ |
|

   

 
   


   

7
  

 
 

  


 

  
  



 
 

 

   

 
  

 

 
      
 
   

   

× { 
   
     ! 
V   ? 

!
   ! 
 ?
V


                
© V 
  
  
 

:  
  
 
  

  
   


    
 

 

{ 


 



 


 
  
    
  

 


       

 

a  
  






,index.Ovalue

a 


©   



      

 
  


 <elem=
 

Î 

  


     4

5 6

- {  


   


8 {    
   
9     
/ 



¦ 

{    

 



 
    

Option 1 is incorrect. In the syntax of the shell command interpreter, the J positional
parameter references a command itself. However, it acquires a different meaning in
the syntax of the awk command interpreter.

Option 2 is incorrect. The first field in a line of input is referred to with the $1 field
descriptor.

Option 3 is correct. The $0 field descriptor matches every field in a line of input. The
default field delimiter is a space, but you can use the ÑF option to define the field
delimiter.

Option 4 is incorrect. In awk, all variables have a null value until a value is assigned
to them.

Î 

 
 

  

4

5 6

-    



 
  


  
8 a   



  
 
  
 
9 a  (
   
 


   

 
/ a  
   
 

  
  
 

¦ 

{ (
   
  
   
  
 
   
 

  
 

Option 1 is incorrect. Irrespective of the number of files on which the awk code
operates, the END statement is called only once, after all the input has been
processed.

Option 2 is incorrect. As is generally true of shell scripting, awk variables can be


initialized as you need them.

Option 3 is correct. You can use the BEGIN statement to perform initial operations,
such as creating columns or assigning values to variable, before processing any
input.

Option 4 is correct. Once all input has been processed, you can use actions defined
in the END statement to manipulate the processed data.

X    

5  
 
    
    
 

:  
  

    
  
   
 !



  <=!
    

   

{       ©   V    A@ 
 A 
 
 


 
  
    

#*

 
  
  
 
   
   0G


 a  *
   


7    
     
      


    
 0G



{       ?  "   

a 

  
 
   

         


 

:  
              

   
   
   
 
 


-

 
  3 
    3    
a  3   
  


   


 

      
  

   
  

  

{   )     V   
 
  


  
 

     
  

      

   

    
     

       


 
     

Î 


      

  
 

 
  
 


             4

(   
€    
   ( ©     ’? ?   )  

5 6

- {   


  
 
8 {    
  
 
9    

  
 

¦ 

{   
 
   
  
 
   
 

Option 1 is correct. Each time a blank line is detected, the awk program initialises the
 variable with a value of 0, and increments it by one. The print command sends the
value of  to standard output, accompanied by the text strings enclosed in double
quotes.
Option 2 is incorrect. The regular expression that increments the  variable - J -
matches every blank line, not lines containing characters.

Option 3 is incorrect. The print command only prints the value of the  variable and
some helpful text. The pattern that is matched ± in this case blank lines ± is not
automatically printed.

a 

    
 
V
 

 
V              
  -    
 

 {    
 
  
 
8

 


     

  

  
   


 


 
  

 
 
  
  

 
  

 
  

   
 


5  
 
    
  
   
 : 

  
     
       

 
   

  

{     

){  )

)    )

)    )

)A ¦   )

)X    )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))


c
     
    

¦  


    
 

   
  

   

       

{   
 
 

 
  

a 
 
   !    |@ !
   
 

   

{   
     
 
 
 
 


a 
       
 
 


|  
  

×

 

×    
×  
  
 

   
  
!   !
     
  
 
3 

a 
     



    3  


    : {
   <:{ =
 
   
  
 

 
a 
  
    

  
    
   
 
  
  

5  *   


  
   

 
@LL

P

     
 
   
 
  
|   
       
 
  

{ 

   
 2
 
    
   
 

  

 
      
  

| 
  
 
     

2 
 
 
 
  

 

  


Î 

 

    

 
@@LL P


 

    

:           


  

  

 

    4

5 6

- @
 

     
   
  
8 Ú    


 
9     
 
/ C
 
 
  H
J    


 

¦ 

a       




       
  
     


 

 
 
 
H

Î 

C
  
   


5 6

- 
 
8    
9 |   
 

{
6

 Ú   
    

 
7 5 2
       2
   
@ |   


  


¦ 


         
       


  

    
  2
      
 
 2
  
  

  
  
 
Repetitive tasks can be automated by shell scripts. For instance, if every project you
work on has a similar directory structure, you can automate the process of
generating the directories for a particular project.

Because shell programs are relatively simple to write, it's often useful to test
procedures in the shell before incorporating them into programs written in more
sophisticated languages.

Services and system configurations on UNIX systems are usually initialized by shell
scripts, so understanding shell programming techniques is essential to optimizing
your system.

A     

 
  3 
      

 
 
 a  
   
  
3    
 
          3 


H
 
  

 
   
  
  

×    
×       
×    

  

   


{    

 
      
    
  
 

  

     
       


  3  
    


         
a  
 

    !
 

   !   


 
       ( 

     
      
      
 

     
     
 
       
a  


   
  



: 
  
 ©  © 
  
  ? 
 
  
 
 *   3     
3  
 

@  


   


!       !  
×   

 
×   
×  
×



    
a    

       
    
 


a  ©  ? 
    
   
    

 

       

  


         ©
   


  

    ©
 

 
 ? 
   

 3
 

  
  
:  !
  
    !    
  

 

 
 
 
   { 
  
  


 
 
  



   

 
  

 
  
        
   
  

 
  
 
  

     
     


 
   VV ?   



 


    

 

 


{         6

 A 



-G6A

Ë#(
 D
<=

 ,"Ë#(!-G.
 
 A 



-G6A

Ë#(
 
 A{ 
 
  "Ë#(A
M
 D
Ë#(

a       
 
 

 

  
  

 a 

 
  
   

       

 
 -  

    

 
     Aå  A    
 
   

 J 
    Aå  A 
   

 3
 J

{         6

 A(
 A

C
@5{O-
 ,"@5{"C.
 
 Aå  A
@5{O"<<@5{L-==
 
 
Ë





  

    
 


a 
 

 


 



C  ! 
 E 
7
  !    

  
  


 
     a 
 ?V?  
  
  



 


  
  {   

 

    


 



  
 
 *
  a 
  
   

         
 
 2





Î 

  


 
    

 

5 6

- Ú 
   *    
8  
 
   

  
9     
 
 
/   
 


¦ 
  
  
  
    
 
        
     
 
 

Option 1 is incorrect. To reduce errors and save time and effort, you should debug
code as you write it.

Option 2 is correct. Although use of whitespace and indenting is not a functional


requirement, it makes debugging and maintenance considerably easier.

Option 3 is correct. Creating modular code through the use of functions makes your
code easier to maintain and reuse, and thereby improving efficiency.

Option 4 is correct. Psuedocode is particularly useful for organizing your approach to


complex programming tasks.

Î 

     4

5 6

- { 
     
8 {     
 
 

9 { 
   



¦ 

       


   


Option 1 is incorrect. Pseudocode is not interpreted, so it can't be debugged.

Option 2 is correct. Although pseudocode isn't needed for simple tasks, it is difficult
to accomplish complicated programming tasks without first breaking them down into
steps.

Option 3 is incorrect. Pseudocode isn't included in your actual program, so it doesn't


affect the readability of your code.

 

{  
   
    
 
  a 
 
           
  
  3 |  

 

 
 
    

    

  
 

{     
  

   

  

  H
 
  
        
  
 

    
    

  

{     

){  )

)    )

)       )

)A     )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

{        c
 
    

¦  


    

  
 

  
   

 {    

 
3 
         

  
   

:  
     


 
   
  
   
 
      
  


   

{   
        
     
     
       

Î 

a   

    
 


   
    
 4
5 6

- Ú      


8 (

 
 
  
9 (

 
 
  
/ {  
 

¦ 

a 
   
  


 
 




 
 
 

a 
   
       
6

× ,
 .
× 
 
× ,,
 ..

 
expression     
 
 a    


  
 


  
  
 
 
 G     

  

 
 -   


{ -- * 
 
   
- * 

  


 

:  
    
 

   
- * 


  

      

 

:  
 

 
   
*



  
   -- * 
 *     3  

: 
 
   
 3
      

 6

,,""..

,"".

""

@           

×  

 
 ½ ££ 
A
A
×    
 ½   
A A
: 
 
      
  

,,expression1++expression2..

| 
 
 
    
    
 

 

* 


   
 


   


 
0G

$[[ $class_mark > $class_average && $class_mark > 80 ]] \


&& print "Your class mark is very high"

a 
 ,,R..
      
  



{      


 
    


 
 



 
 

6

× !      2 


× !    
× #!     2 

{     


          Ë

 

 


  

set_var (){
echo "Enter a variable"
read VAR
}
while [[ -z $VAR ]]
do
set_var
done

Î 

  


 
   




5 6

- |
      -  
    
8 {      


 -  

 




9 a 
   
 
   
 

/ { -- V   
 

 
    7  

¦ 
  
-  


 






@   
 
  
    

 


Option 1 is incorrect. The - and symbols are commands, so if you neglect to


include white spaces on either side the shell will return a syntax error.

Option 2 is correct. The shell returns a value of 1 when a condition evaluates as


false. The Ñ option is used to test that a a variable has been assigned a non-null
value.

Option 3 is correct. You can use the && operator to require two conditions to be met,
and you use the || operator to require only one of two conditions to be met.

Option 4 is incorrect. The -- ii syntax is supported by the Korn shell,


but not by the Bourne shell.

A     

a 
 
    
     
,,string1Ostring2..

: 
      A7 2A

   
"|((


  
   
A  


A

[[ $DESTINATION = "Belize" ]] && print "flights available"

a 
      
   
 6

× O
× NO
× '
× %


a  ,,
O ..
    
 
 


  
  
   


@       6

DOTW=$(date +%A)
[[ $DOTW = S* ]] &&
echo "Weekend "

 
  
    


 
 
A|

A

A
A  %

{ %

      

  
A|A
     ANA  

a  ,,
NO ..
  
  *
 

{ 



   
 
    


@       6

DOTW=$(date +%A)
[[ $DOTW = S* ]] &&
echo "Workday "

 
 %

       
  
A|A

  *  A 
NA  

a  ,,
$'
%..
   

  -  


  8    


{   
   

     


 

      


   A
A
   

@       6

SMALLER=$(abc) [[ $SMALLER < bcd ]] && echo "Smaller"

    A
 A 

A A
      
A|
A

a  ,,
$%
%..
   

  - 



  8    


@       6

BIGGER=$(bcd) [[ $BIGGER > abc ]] && echo "Bigger"

 
  A A 

  A
 A     
 A7 A

a       <  


,,option filename..<  6

× <   


  
× <   
  
   
× ©<   
  

 
× <   
  


× <   
   

× <   
   

×  <   
  




×  <   
 

Ú   

{   
 
AA 


 
  *       

  
 

[[ -s new ]] && print "The file contains data"

  
   
 E      
   

× 
× 
× 
× |


{ ,,H
 ..

 
 G      
 
 Ú   
     Ú    

{ ,,#
 ..

 
 G      
 

         
     

  
 
  
       
 
|    
   
  
    

{ ,,5
 ..

 
 G  Ú     

    Ú    
|
{ ,,|
 ..

 
 G      
 

 | 
    
     
 


        
  
 
      

6

× ,,
 $
 %..
× ,,
 $
 %..
× ,,
 $ 
 %..

%% ÷  ÷ &&


{  ,,
 $
 %..

    
 

%% ÷   ÷ &&
{ 
,,
 $
 %..    
- 
 
8
%% ÷  ÷ &&
{ 
,,
 $ 
 %..    
-  
 
8

Î 

| 
 *  
 


 a 
 

 

A  A
 
  
     



 
 
   
   
   


 




       
   

 4


-- MISSING CODE ££       ? © ?

5 6

- 
   
8  
 
9   
 
/  
 

¦ 

a  
 [[ currentfile -nt backupfile ]] && print
"Overwriting older file" 
  
     

 
     

{  
            
 6

× ·
× 
× ?
× 
× 

·
a  ·     
,,$3%..    - 
3
  8

{ 

 
 
  

 I/ 
 
  

[[ $age ±ne 64 ]] && print " Your age is 64"

a       
,,$%..    - 
 3
  8

[[ $age ±ne 64 ]] && print " Your age is not equal to 64"

a    

 
 
  

  

I/ 

?
a  ?     
,,$%..    - 

 3
  8

{ 

 
 
  


  I/ 

   

[[ $age ±le 64 ]] && print " Your age is below 65"

a       
,,$%..    - 


 3
  8

[[ $age ±ge 64 ]] && print " Your age is above 64"

a    

 
 
  

3
  

 I/ 


a       
,,$%..    - 


 8

{ 

 
 
  



I/ 

   

[[ $age ±gt 64 ]] && print " Your age is above 64"

Î 

| 
 
  
 
A
A 

|  
   

     

  ?V?’  
© MISSING CODE


¦ 

a  
 [[ -a travel ]]      
A
A 

Î 

| 
   
A
A  
 
  




|  
    3    


  ?V?’  
© --   ?

   © ?   
© (||( 

   © ?   
? 
   © ?  
©
? 
   © ?    
©

¦ 

a [[ -s travel ]]   


   




Õ
 
    
   7
  

$ 

The Bash shell supports the use of single and double square brackets  and   for
conditional testing. Double square brackets are a recently added feature, and are
slightly more versatile.

The Bash shell supports the following arithmetic test options:

? ± less than


? ± less than or equal to

 ± equal to

g ± greater than or equal to

g ± greater than

 ± not equal to

Î 

  
  
G   
     
4

5 6

- 
8 
9 
/ 

¦ 

{ NO  


  

    

 G   
  

  


Option 1 is correct. If variables X and Y have different values, the test shown here
will evaluate as true, as represented by a return value of 0:
-- J != J

Option 2 is incorrect. This operator will return a value of 1 if the two strings have
different values.

Option 3 is incorrect. This operator will return a value of 0 if the string on the left of
the operator has a greater value than the string on the right of the operator.

Option 4 is incorrect. This operator will return a value of 0 if the string on the right of
the operator has a greater value than the string on the left of the operator.

Î 

C
      
          

5 6

- --  © ? 
8 --  © ? 
9 --  © ? 

{
6

 { 
  
  




7 { 
  
  
@ { 
  
   


¦ 

{ !
  
 *   !       




 !  
    


A test using the Ñ option on a filename will evaluate as true if the file exists.

A test using the Ñ option will evaluate as true if the file is not empty.

A test using the Ñ option will evaluate as true if an executable permission has been
set on the file.

 

{ E  


     
       a 

 - *   
 -- * 
    

 
{ -- * 
 

  
 a 

      
3   
      
    

½    ½ 
 

a 
 
    
 
 
      E  
{ 
   
 
  
 

{     

){  )

)    )

) {    )

)A     )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c  c
      
    

¦  


       
  
 

 $  

a    

              

@   

   
 
  © 
  © 
? 
  ©  ? ©

 V 


a   © 
  3
 
    


a   © 
   


if condition
then
commands
fi

{   
  
 
 

 A
 G-A  
    

 

 
 3    
 

Aa 
 A

 /usr/local/bin/ksh
echo "Enter password"
read password
if [[ $password = password01 ]]
then
print "You can proceed"
fi

{  ©  ? 

    
  
 
       


   
    
   
a   ©  ? 
   

condition
 
commands

commands
 

 
 
 
           
©


 

     
!



   
A
 G-A! 

 
 ?      
  
AH A
 
 

 /usr/local/bin/ksh
echo "Enter password"
read password
if [[ $password = password01 ]]
then
print "You can proceed"
else
print "Goodbye"
exit
fi

{  ©  ? ©

     
     

 
       

   
 
3
   

    

  
 
   ?   

condition1
 
commands
 condition2
 
commands
 condition
 
commands

commands
 

 
 ? ©

   
  

  
     {  
        
  
 /usr/local/bin/ksh
echo "Enter password"
read password
if [[ $password = password01 ]]
then
print "You can proceed"
elif [[ $password = password01 ]]
then
print "Please retype password"
read password
if [[ $password = password01 ]]
then
print "You can proceed"
else
print "Goodbye"
exit
fi
print "Welcome $USER"

{ V 

 

 
 
    
  


      
 


   

  


value 
pattern1=command
command;;
pattern2=command
command;;
patternn=command
command;;



{ E     


  
 V 
 

{        

 




  
   

                

  
  
 
 
 

 

echo "Enter password"


read password
case $password in
admin01 ) print "Administrator rights are assigned" ;;
password01 ) print "User rights are assigned" ;;
read01 ) print "Read rights only" ;;
esac

Î 
| 
 
  
  

 

 
 
 
 
   

|  
   

   
   

 



 /usr/local/bin/ksh
echo "Enter menu number"
read menu
MISSING CODE
1 ) ./travelpackage ;;
2 ) ./flights ;;
3 ) ./bookings ;;
esac

¦ 

a V      V 




   

   
 


Î 

| 
 
 

      
 


A  A

|  
  

  

 /   
 



 /usr/local/bin/ksh
echo "Enter menu number"
read menu
1 ) ./travelpackage ;;
2 ) ./flights ;;
3 ) ./bookings ;;
MISSING CODE
esac

¦ 

a  V    



     
   
 

A  A

Î 
    

 
      
 

   

     
4

5 6

- ©  © 
8 ©  ?  © 
9 ©  ? © © 
/ V   V

¦ 

{       


   
      

 
 ©  ?  © 
 

Option 1 is incorrect. This statement only executes code if a condition evaluates as


true.

Option 2 is correct. This statement executes code after  if the specified
condition is met, and after ?  if it isn't.

Option 3 is incorrect. This statement is useful if you need to use additional conditions
after the ?if syntax.

Option 4 is incorrect. This statement is used to execute code based on whether one
or more patterns match a particular value.

A        

# 
   
 
 
       { 
  
 
   # 
     
    
       
      

a     
 
 
3 
 

 

  
 

a  ©
   
  

    
 

  
   
 
  
  
A
AA
A
A

A
{ 
 
 
 
 
   

 variable word1 word 2Rwordn


 
commands
 

: 
 
  
  

  

 
 


    

 /usr/local/bin/ksh
integer loopnum=1
for x in a b c
do
print "Loop $loopnum: x=$x"
(( loopnum+=1 ))
done

{        

Loop 1: x=a
Loop 2: x=b
Loop 3: x=c

a 

 

 
 


     
 

     


 /usr/local/bin/ksh
for FILE
do
chmod 700 $FILE
print "$FILE is executable"
done

 

 
AA
 

  
A
A  


 
  
  


  ?

{ 
    
   
  
  

& filename1 filename2 « filenamen

 
  ?
     
      


 condition1
 
commands
 
  
     

  2  
 
 

 

: 
  
       
     

 /usr/local/bin/ksh
echo "What is the name of the directory"
read directory
echo "How many directories do you want to make?"
read dirnumber
count = 1
while [[ $count -le $dirnumber ]]
do
mkdir $directory$count
(( count+=1 ))
done

 
   ?
     
     
  

 
    
     
condition1
2  


 condition1
 
commands
 

Î 

| 
 
 
E    

    
{
  
 

 
  

  
  |

 



   
 
3      




    
  *  


          4


 /usr/local/bin/ksh
integer y=3
while (( y < 5 ))
do
print "The value of y is $y"
(( y = y + 1 ))
done

5 6
- { 
  8
{ 
  9
{ 
  /
8 { 
  9
{ 
  /
9 { 
  9
{ 
  /
{ 
  J
/ { 
  /

¦ 

{   

  9
     
  
J{ 
  
  6
{ 
  9
{ 
  /

Option 1 is incorrect. Although y having a value of 2 meets the conditions of the test
on which the loops is performed, the first line of code assigns a value of 3 to y.

Option 2 is correct. The first iteration of the loop prints the current value of y, and
then increments it by 1. The second iteration prints the new value, 4, before
incrementing it.

Option 3 is incorrect. Only two iterations of the loop take place, because after the
second iteration the condition on which the loop takes place is no longer true.

Option 4 is incorrect. The statement that prints the value of y is executed before y is
incremented, so the first iteration of the loop prints the initial value of y, which is 3.

Î 

 
      

    4

5 6

- {              
   
   
8 #    
        
    
 
9 a      


   
 
© 
/ a   
    ? 

¦ 
#    

    
      
   *       a   
   
 ? 

Option 1 is incorrect. Loops can be infinite, so you should take care when specifying
conditions on which they take place.

Option 2 is correct. You supply parameters to the fr loop on which code is
executed, and you specify a condtion for which i? loops take place.

Option 3 is incorrect. You can dynamically assign parameters to the fr loop. For
example, you can use command-line arguments to assign them.

Option 4 is correct. You can use the   command to specify a condition, which
while it holds true, will cause a i? loop to execute.

 

{                



 { 
 
 
  © 
  ©  ? 
  ©
 ? ©

 V 


  
 

 !  
!
     

         
     
 

{     

){  )

)    )

) $  )

)A        )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c       c


  
    

¦  


    

  
   
  
   

  

   *3     


 
    
 
 


{        


6

×   
  
×    
  

A { ! "    

| 
 
  

  
   

    

    


:    
E    
   
  

{   
       


  

        
 
    
  
    
     
   
   
     


Î 

#*

 
  
  
  D

   
  

 


|  
   
    

 
  
  


  ?V?’  

  V  V ©   

MISSING CODE

 &

VV
¦ 

a   function check_date { check_date {   


     

Î 

a 
 
      


  

|  
  
 
       |



|



  ?V?’  

 V  V ©   

© V 

 &
© --  |  (||( 
 | 

  ©? 
©


VV

¦ 

{  
 
       |


|
 ))

Î 

a 
 
  
 


|  
   

    


    
   
 


  ?V?’  

  V  V ©   

© V  VV

 &
© --  |    | 

  ©? 
(||( 
©


VV

¦ 

{  

 


      
 else

Î 

{        

  
 
  

    


|  
   

  


  ?V?’  

  V  V ©   

© V  VV

 &
© --  |    | 

  ©? 
? 
    
(||( 



VV

¦ 

{  

 

 

O

X { A! c      


   VV        
 

 
 
          
 
     
8/ 

================
Function: checks what files are modified today
================
function modify {
find /home/vincep ±ctime 1 > logfile
if [[ ±s logfile ]]
then
print "No files were modified"
modified=false
else
print "Files were modified"
modified=true
fi
}

Î 

a  
     
  
    
 

    
   
  
 

   

|  
   

   
     


  ©? 
VV
© --    

       © © ?   ©  
(||( 

¦ 

a modify 
 modify  

Î 

a 
     
 

     cat



@     


 
        


  ©? 
VV
© --    

       © © ?   ©  
 ©
MISSING CODE
©

5 6

- ,,N"   OO..


 
 A{     6A

  
 
8 ,,"   OO..
 
 A{     6A

  
 
9  ,,"   OO
..
 
 A{     6A

  
 
/  ,,"   OO..
 
 A{     6A

  
 

¦ 

{     
© --  ©   

    ©  © ? )
V ?© ?
© 

Option 1 is incorrect. The use of the ! operator on the first line means that the
condition evaluates as false if files are modified, whereas you need it to evaluate as
true.
Option 2 is correct. The first line tests that files have been modified. If this test
evaluates as true, the rest of the if fi statement is executed, printing a list of the
modified statement accompanied by a message.

Option 3 is incorrect. The loop executes if files are not modified, in which case there
will be nothing to print. Also, if the condition is true, this loop will be infinite.

Option 4 is incorrect. To avoid infinite looping if the condition is met, you need to
include the following command at the end of the code that is executed by the loop:
ifi=f? 

a 
  

  
    
 

{  
         
   
   
     
 V
{        
    
   

return=false
check_date
if [[ $return == true ]]
then
print "Finding out if files were modified today"
modify
if [[ $modified == true ]]
then
print "The modified files:"
cat logfile
fi
fi

{     

){  )

)    )

)  )

)A { ! "     )

)X { A! c      )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))


$    c
   
    

¦  


     
 
 

  
 

      

   
 
   

 





  
 
 





:  
 
  
    

   
 
 
    
 
 

 

: 
  
    

   
 


   

function md {
mkdir $1 && 'cd' $1
}

   
 
       
  
  
    

:      




×  
      
× 
 2    

         


:   

  
 

   
 
  * 
    
 
     
 -    
:   
 2      
    


    







:  
    

3  



: 
 
 

    
  
     

  name?
commands
M

   


·  
  
  
 3 
  
Aå  A

 /usr/local/bin/ksh
function quit {
exit
}
print "Hello world"
quit

{  
          

 
  3 

 /usr/local/bin/ksh
function get_time {
TIME=$(date +%m/%d/%y-%H:%M:%S)
printf "$TIME\n"
}
get_time

a 
 




 
      
   
  


   

 E    

7
  




     {    

 

 /usr/local/bin/ksh
x=1
function myfunc {
x=3
typeset y=4
print "In local function x is $x"
print "In local function y is $y"
}
myfunc
print "Outside local function x is $x"
print "Outside local function y is $y"



You can declare functions using the Portable Operating System Interface (POSIX)
format shown here to maintain compatibility with the Bash shell. Functions that have
this format cannot contain local variables.
The syntax for doing this is

function_name() {
commands
}

a 
  
 

 
 
       
E  7
    

{  
 


variable

a 
    
 *  
 

  
 
  
 
 

{ 
   


 
  
  


    

 /usr/local/bin/ksh
function get_number {
print "Input a number between 1 and 9"
read num
case $num in
+([0-9])) print "Input is numeric" ;;
*) print "Non-numeric input, try again" ;;
esac
}
get_number
print "The number is $num"
integer answer=$num*5
print "Five times number is $answer"

Î 

        


    
4

5 6

- 7
 
    
8 7
 

    
9 7
     
/ 7
 




¦ 
:      
    

 

  
 

Option 1 is incorrect. While functions do allow you to reuse code, it is the fact that the
function's code is copied into memory that improves performance.

Option 2 is correct. When a function is first declared it is copied into memory, from
where it is executed whenever a script calls it. This is more efficient than reading the
code from disk.

Option 3 is incorrect. Functions don't have to include control flow stuctures.

Option 4 is incorrect. Functions can use local or global variables, and there is no
significant performance gain associated with either.

Î 

  


      

5 6

- :  



  
   


8 :  
   
   
9 a 


  
  
/ a 

 
        

¦ 

:  
   
    
      

  
   
 

Option 1 is incorrect. You can use the rur command to specify a return value for
a function.

Option 2 is correct. Functions can be defined at any point in a shell script, as long as
it is before they are first called.

Option 3 is correct. It is common for a function to accept arguments, which are


supplied after the function name when you call the function.

Option 4 is correct. You can store a function in an ordinary text file and use the
command to read it into memory.

A c    
:  

   




×  

×      

  
a  
    
  
   

a  
        
 
     

 

    

 
  !
 !    

   


function get_time {
TIME=$(date +%m/%d/%y-%H:%M:%S)
printf "$TIME\n"
}
     
a         
 2



:  


 
 

   

7

  



 
   

a  
   


   : 
 


     



    

   
 
 

     6

 /usr/local/bin/ksh
function get_number {
print "Input a number between 1 and 9"
read num
case $num in
+([0-9])) print "Input is numeric" ;;
*) print "Non-numeric input, try again" ;;
esac
}
get_number
print "The number is $num"
integer answer=$num*5
print "Five times number is $answer"
a  
 
 
      

: 
 
     D 
   

5  

    
    
     


  shell_script

 E   


     
   ©  



: 
 
    ’  

function get_number {
print "Enter a number from 1-9"
read num
case $num in
([0-9]) ) print "Thanks"
* ) print "Try again "
esac
}
typeset ±fx get_number

a 

 
      
  
  
  
    
   
     
 

   

  
  

a 

 
  

   3

{ 
 

       

   
  
   
  

{  
 
      

     
 



  
        
 
  

  
     

{ 
 

    


!function_name

Ú     
 




a 
    
    *
   
    
Õ
 
  

       
 



   
  

: 
  
         

     

  
   

Î 

| 
 
 
    

 

  

 
 


         !   
  !  

 


  
I4


  ?V?’  
© V   ’
     ’ © 
  
V    

-      
       
 V

 ? -   - 

 ’


·    
     ·  ) · 

5 6

- 
! ·  !
8    
9   

! ·  !
/   
! ·  !

¦ 

{       


  6
  

! ·  !
Option 1 is incorrect. The user first enters text, which matches the "catch-all" pattern
in the   statement:

 pri "Try gi!"

Option 2 is incorrect. The while loop ensures that the gur function is
executed repeatedly until the user supplies a value between 1 and 9.

Option 3 is correct. Once the user has supplied a valid value for the u variable, the
i? loop exits because its condition is met, and the code that prints the square of
the u variable is executed.

Option 4 is incorrect. The gur function provides feedback when a suitable


variable has been entered.

 

:  
 
  
    :     
 
  





 
 2    
 


   a  
     
5
 
| 
< 5|= 
 

 
      7
  

a 


   
       
 
 
   
 
       
 

 
E       { 

  
 
        

   
 

   
 
   

{     

){  )

)    )

)      )

)A c    )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c    c
  
    

¦  


    '(
  
 

 c      

(
 
      
  
 
 

  
     


{    
 
  


{  

  
 


× 

 
× 

 
× 

 

    
{ 

   

 

 
 
7
 


 
   


    
{ 

   
 
   
  

7
 


     
 
 
  
{ 

      
 
   
  7
 

     
 


a            ! 


 V
 
   

{ E  





         


× G   



 < =
× -   

 < =
× 8   

 <=

 
    

      
6

input8%standard_error_output

a 
   
 & <&5=!      

 
 

   


 !    
a 
       
6

×    



  
 
×  


  
 
×    
  

    V?’’ 

×    

  
 
×    

 

a 
        
 
 :  
  
  
      
 
      
  
 

- 
    



 
  V        
   
 
  
   

a 
A A         

  

{ 
      

  

 <  < 
 =

{  
    
   
 
 
  

    

!   
  !
   


 

 

 
V  V     


  
  


  
      

 
  /

{ 
 
    

command''word

:  
  
  

 
  
{#

C

          ?
     
    !  


Î 

a 
   
  
   



   
 *     
 

   4

5 6

- V
8  
9 · 
/ 

¦ 

{ 

 *     
 

   

a 
   
  
       6

×  
× 
×  
×  


{         

   
  

{           

 ½

   
 




{    
   

  
    
   
 
{    
   

         
   

{   
 
   
   !   
 
   !  

a 
   
       6

× 
× 
×  
× 
× 
×  
×  


{   
    
       


 
        
  

{       
 
     

{    
     
  
  

{   
      

 ½
   

{   
      

 <$=
   


      
  
  
  

{    
       
      
 
{    
     
         

a 
       

 
  
   
 

 

:  
   ?   ´?   

  
   !  


    &    !  ? 
  
 
 



If the file named ls.out already exists, the old version will be overwritten. To prevent
this, you can append content to the end of a file using the  command.


  
     
  
 
*

  
 



:  
   E      & &
 
  
 

 D 


  
 
 D   


  V      ? 

Î 

C
      
       

5 6
- %%
8 %
9 %)

{
6

 

  
   
7 Õ  

  
 
@ Õ  

  
    
        
  

¦ 

{ %  

  
   

 
 
 
    V?’’     %) 
 a 



  
    %% 
 

You can append the output from the ? command to a file named ir?i  
with this command:
?  ir?i  

You can redirect the output from the ? command to a file named ir?i  
with this command:
?  ir?i  

Even if the ?r option is set, you can redirect standard ouptut to overwrite
an existing file called ir?i   with this command:
?  ir?i  

Î 

     


     *
 

 ½ 
 




  
 4

5 6

-  
8 
9  
/  

¦ 

a       



 ½  





    

Option 1 is incorrect. The r Ñp option is used to accept input from a co-process
spawned using the  operator.

Option 2 is correct. If the option is not inserted, the backslash causes special
characters to be treated as literals.

Option 3 is incorrect. The r Ñ option will cause input to be saved in the
command history file.

Option 4 is incorrect. The r Ñu option is used to specify the file descriptor used
to provide input. The default is standard input, as in r Ñu .

A      

#*

 
  
 
 

 

 
  


Ú 
       
    
  {    
 
 

< 

*


 <
    
  

    
 


    


 

  

  :{  !  *3  
*
 
 !  
  !  3 
 
 

|          

 

 
V
 
 
       3 Do
you want to perform an anonymous ftp [y/n]:   

a   
  




 
 *
!  !   

{ 
 


      

V * 
   
 ? * 
 

(
 


  
  
     
   
   {      
  

   
 
    
 
  



{ 
     
  

!  !  

© * ? 
   
    

 
   
   
 

!(

||%{ 
 ( A
  A
||% * 



echo "Do you want to perform an anonymous ftp [y/n]:
read ANON

while [[ $ANON = y && $ANON = n ]]


do
echo "Enter y or n, please: "
read ANON
done

if [[ $ANON = y ]]
then
FTPLOGIN=anonymous
PASSWD=" "
else
echo "Enter the username to use: "
read FTPLOGIN
echo "Enter the password to use: "
read PASSWD
fi

Î 

 :{  



3  
     

 
 
       
a    V * 
  
    



 

        
 4

5 6

- 
8 (
9 ||%
/ 

   *  


¦ 

a    (


||%

    *



 

5   

 

 
 
     
 
     
   

 



    

{ 
  
       * 
     

 

!|Ë
(!  
   
 

echo "Do you want to perform an anonymous ftp [y/n]:


read ANON

while [[ $ANON = y && $ANON = n ]]


do
echo "Enter y or n, please: "
read ANON
done

if [[ $ANON = y ]]
then
FTPLOGIN=anonymous
PASSWD=" "

print "Enter the address of the FTP server: "


read FTPSERVER

print "Enter the file to transfer: "


read FILE

{ 
   
 
  
:{    
     © 


 *
   
 

 


{     
     
 
 :{  
  

 


(
ftp -n <<- END
open $FTPSERVER
quote USER $FTPLOGIN
quote PASS $PASSWD
binary
cd /home/gregl
put $FILE
END
)

#*

 
   

   
 

  

 
  
-KG-GG88

a      
   
   

$ ./ftp.sh
Do you want to perform an anonymous ftp [y/n]:
y
Enter the address of the FTP server:
190.100.2.2
Enter the file to transfer:
case.sh
$

Î 

a 
  
   

   
 

  
 

  

   
 



 


 
    VV  ) 
 V 

5 6

- V
8 
9    
/ 

¦ 

a  
  
 

 

 

Option 1 is incorrect. The  command will merely print the string NAME to the
screen.

Option 2 is correct. The r command will provide a prompt, and input at the
prompt will be assigned to the NAME variable.

Option 3 is incorrect. yp  Ñ is used to export a variable, not to receive input.

Option 4 is incorrect. The  operator is used to open a here document.

 

 

     
  
 
 

  
     

{  


 

 


 a   
         a 
      
  


 
  
   
 
 

a 
  

 & <&5=  : 
 
 


 



 

 
  {  

 



  

    
 
 

    

{     

){  )

)    )

) c      )

)A      )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

c     c
  
    

¦  


    
   
   
   

        

{  ?V

    

  

  

  
 
{   
   
 

  





The ? command is available only in the Korn shell and version 1.14 and later
of the Bash shell.

a  
 ?V
  
   
  

     
  
 * 
  { 

 

 
     
 
   
 

 name1 name2Rnamen
 
commands
 

Î 

{  ?V


  
 
     

  

|  

 
  ?V
   

 
       3 

 
 +

 (  


      


7    
 

@ 7
   

  


Ú |      


  


'

¦ 

   
 +

7    
 

Ú |      


  


'

 (  


      


@ 7
   

  


A    

#*

 
  
   

      
   

       

  
  

   

 

  

 


| 

a   
 
  <   
 A  4A< 

 
  

{     | 

   
 


  

 /usr/local/bin/ksh
PS3="Select an option [1-3]> "

a 
    A|  AAÕ  A
A( A      

 

  

   
      
     
(


     '



 /usr/local/bin/ksh
PS3="Select an option [1-3]> "
select OPTION in "Show files" "Run editor" "Exit"

{  * 
    ?V
  
 

  
*   
        

 
   
        <   
 3    <  ?V
    
a   
 
 ©? 
 

 /usr/local/bin/ksh
PS3="Select an option [1-3]> "
select OPTION in "Show files" "Run editor" "Exit"
do
if [[ $REPLY = 3 ]]
then
exit

Î 

#*

 
   
   
   
   
     



    
       4

5 6

- V
8 
9 ?V
/ · 
¦ 

a 
V
          
  
  

{   
  !  
   
    -
8< 


V
 
   
 
    
     

 /usr/local/bin/ksh
PS3="Select an option [1-3]> "
select OPTION in "Show files" "Run editor" "Exit"
do
if [[ $REPLY = 3 ]]
then
exit
else
echo "You chose to $OPTION"
fi
done

     ?V


 

   
  
 

  *   

$ ./select.sh
1) Show files
2) Run editor
3) Exit
Select an option [1-3]>

#*

       -

{   
Aa   |  A
   

$ ./select.sh
Show files
Run editor
Exit
Select an option [1-3]>
You chose to Show files
Select an option [1-3]>

{ 
  
  

 ?V

 
V 
     
 
 © * ? 
 

   V 
       

  
V
 
   


   
   
½ 

 /usr/local/bin/ksh
echo "1. Menu item one"
echo "2. Menu item two"
echo "3. Menu item three"
echo "Choose an option [1-3]"
read MENUITEM
case $MENUITEM in
1 ) echo "Do action 1" ;;
2 ) echo "Do action 2" ;;
3 ) echo "Do action 3" ;;
esac

{        V 


   

$ ./case.sh
1. Menu item one
2. Menu item two
3. Menu item three
Choose an option [1-3]

Î 

  


 
   ?V


5 6

- {    ?V


   |   



8 {  ?V

     V 

9 {  ?V
 


  E 
@ 
/ {  ?V
 '

   

¦ 

{ | 

     ?V


?V
     '

{  ?V
V 


   

Option 1 is correct. The shell's interactive prompt is determined by the S variable.


The Korn shell default is 

Option 2 is correct. The   command can be used instead of if  ? 


statements to execute code based on the user's menu selection.
Option 3 is incorrect. The ? command is supported by the Korn shell and
recent versions of the Bash shell, but not the C shell.

Option 4 is correct. The ? command presents the user with a numbered menu
and a prompt. The value entered by the user is stored in the RE  variable.

 

a 
  ?V
     

  {  ?V

 


  E  
   --/

  7
  

{ V 
  
  
    


7   
V 
 ?V

    

  
 





{     

){  )

)    )

)        )

)A    )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  ))

"   c
       
    

¦  


   
 

  
  
 

 

   *3   



   


  
{        
6

×       


×
   
    

{ !    

#*

 
  

 


       
    
    3   
 
  

$ ./editor.sh
View files
Launch Editor
Quit
Choose a menu item [1-3]>

   A

#*

 
     A@ 
   ,-9.%A

|  
  
 
  


  ?V?’  
(||(       -  

 

a  |9O 
  

 A  A

|  
 

 

 


  ?V?’  
|      -  
(||(  (  Ë  © ?   V   + 

 

a   
 

 

{ A! ¦       


#*

  
   

  
 

 
       

 /usr/local/bin/ksh
PS3="Choose a menu item [1-3]>"
select ITEM in "View files" "Launch Editor" "Quit"
do

   .

@   
 
  
    


  ?V?’  
|      -  
?V (  Ë  © ?   V   + 

(||( 

5 6

- V  ' 
8 V  ' 
9 V  ( 
/ V  ( 

 

a V  '      

Option 1 is incorrect. RE  is a variable returned by the ? command, so you


need to use the JRE  syntax to expand the variable.

Option 2 is correct. The   command executes code based upon the value of a
variable ± in this case the RE  variable returned by the ? command.

Option 3 is incorrect. The ITEM variable needs to be expanded using the JITEM
syntax. Furthermore, it is more efficient to use the RE  variable.

Option 4 is incorrect. Although this is a possible solution, it requires you to specify


each possible value for the ITEM variable listed in the ? command. Using the
RE  variable, which contains a number assigned to each item in the menu that is
created by the ? command, reduces the likelihood of typographical errors.

 A  .
@   
     
         

      
 
         


  ?V?’  
|      -  
?V (  Ë  © ?   V   + 

V  ' 
(||( 

5 6

-
V  V   V
 
? 
8
V  V   V
 
? 
9
V  V   V
 
?
’ 

 

{  
   
           6

V  V   V
 
? 

Option 1 is correct. The p command provides the name of the current directory as
output. Command substitution is used to insert the output into the string that is sent
to standard output by the  command. The ? command then lists the contents
of the current directory.

Option 2 is incorrect. To perform command substitution, the brackets that contain the
command must be preceded by the J special character.

Option 3 is incorrect. The r command will exit the   loop, causing the
program to end once the user has viewed the contents of the current directory.

 X  .

@   
    
       


        

  ?V?’  
|      -  
?V (  Ë  © ?   V   + 

V  ' 

V  V   V

? 
(||( 

5 6

- 
V   © ?   
 (
( 
8 
V   © ?   
 (
( 

 

{  
 

           6

V   © ?   
 (
( 

Option 1 is incorrect. This command will open the i editor with a file named FI E in
the edit buffer. To achieve the desired result of expanding the FI E variable set
using the r command, you need to perform variable expansion using the JFI E
syntax.

Option 2 is correct. The  denotes that the subsequent code is executed if


JRE = . The  command provides a prompt. The r command allows the
FI E variable to be set using standard input. Once it has been set, the value the
FI E variable is used as an argument to the i editor.

 .  .

@   
       
    
 


  ?V?’  
|      -  
?V (  Ë  © ?   V   + 

V  ' 

V  V   V

? 

V   © ?   
 (
( 
(||( 

5 6

-

8
’ 
9
’ 

 

{  
     
       

’ 

Option 1 is incorrect. This code will simply result in nothing being executed when the
third option is selected ± but the loop will not be exited and the user will be prompted
to choose a menu item again.

Option 2 is incorrect. Each   statement must end with two semicolons, not one.
This code will result in a syntax error, crashing the program.

Option 3 is correct. The r command is used to exit a  , i?, or fr


loop.

  
     
  
     V 



 

   

 /usr/local/bin/ksh
PS3="Choose a menu item [1-3]>"
select ITEM in "View files"\
"Launch Editor"\
"Quit"
do
case $REPLY in
1)
echo "The current directory is $(pwd)
ls ;;
2)
echo "Name the file to edit>"
read FILE
vi $FILE ;;
3)
break ;;
esac
done

{     

){  )

)    )

) )

){ !    )

){ A! ¦       )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

) )  )

"    c
  
¦ 

{

 
 
 

  "   


 
   
 
 
 

 


    
     


  *
  
 

    
 



  
 
a 

 
 
   
      
 

  
 
 


   
 


  
 {   3
 
       
 *   

 
     
 


   

)  

 



  
 
       
  

   
*   
  { 
3 

3  
   



 
 <=
 <D= * 

  *
 
  


 
    
 


  
 


    
 customer_name  

  

 
read.customer.data{ 
    
 


! 

package_name
read.flight.data!  
 
  

 

{   



  
  
   

 <={ 
    
 
     
*
      
   *

  
     
 
  
  


  
    

     read.customer.data   


   

     6

 This function reads a customer's name and contact details from


user input.

*
 
  
  
 
    
  {  
 
 
 
     : 


 

  

 This script obtains data about one or more new bookings using
input functions and then inserts the data as a new entry in the
bookings table

   



 


 

   {  

  

 
  
 


     
 
   
  : 


 
  
 
  




bookingID=$2 unique ID number for the new booking


"  

(  
   

      
 
  a 
   

      
   
  
  

{    


 

   



      

  
  
  a 
  
  

   !
 
  


  

   { *  
 

        
!  
 

   



 
  


 

7
   *    


    
  
 
 
  
a     
    
  
if

  
   
   
 
    


{ 
 
if
     
 6

if [$bool1 = n]
then
rmdir /shared/$tour
echo "Rerun add_tour to start again."
exit
else
touch /shared/$tour/status$tour
chmod 666 /shared/$tour/status$tour
fi

 

   
    
 *

  

{  



     


  


        


  a 

 
 
     
  
 
 
 
 a  


     
 

 

  


     

{     

){  )

)¦ )
)   )

))  )

) )

)"  )

)   )

) )

@   F8GG9| |  #@   


| | 
 | |   


  


| |  #@   |

 
    
     


        

) )  ))

+         c


  
    

¦  


    
    


 {     

5  *  


   ! *
   ! *   


{   
       *
   

:  
  *       



 
   

  

a 
     

    
  



Î 


     
   

2
  
  

4

5 6

-      


8 :  


 
9  
 
/ Ë



¦ 

a  

2  
     : 
  


    
 




  
 
    a 
  
 

 *  

    



 *  


5  *    


  
  

 

 

  
  
      

{       3    
 
  

<     
 

<      

  
   
       6

×  
 
×    
× 
 

 
# 
  

    
 : 

  

 
 

 *
  
 
   

 
  
  

   
   

Copying file file @a to backup directory«
Copying file file @a to backup directory«
Copying file file @a to backup directory«
Copying file file @a to backup directory«
  
Õ      3   
 
*
: 


  
 
 
 *   
   
     *

   

$ user_backup
cp: file: No such file or directory
$
  
|
  

 
 < 
 





  3 

*  <   

$ user_backup
user_backup[3]: syntax error: 'while' unmatched
$
    
    
        
    

   
 

 
*   
 
*

   
   
  å    
 
 

  

 


5  * 
  
   

 
     

a     
    
      

     
 
  
       
     
*   
 *




  

 
        

5  * 
 
 
 
   

   { 


 
   
  
  
        


Î 

C
  
      

5 6

- {  
 

  3 
 *  
8 {  
 
  
 

    
9 {  
    
   
 * 

{
6

 # 
 
7 Õ   
@ |
 

¦ 

     

 
 
 

    
  
    
   
 
 3  * 

  



Syntax errors are generated by mistyping variable or command names, and not
using the correct format for commands.

Logical errors result from design flaws, such as passing improper arguments to
functions or failing to terminate loops.
Resource errors result from a script not being able to access external commands or
filesystem locations ± either because they don't exist or because the requisite
permissions aren't in place.

Î 

        


  2
  
   

 
4

5 6

- # 
 
8 Õ   
9 |
 

¦ 

# 
 

  
   


 
 


Option 1 is correct. Logical errors are usually the result of design flaws. Preparing
your program in pseudocode helps to eliminate this type of error.

Option 2 is incorrect. Resource errors ± such as incorrect permissions, or non-


existant filesystem resources ± are usually encountered during the writing and testing
of a program.

Option 3 is incorrect. Syntax errors are only encountered once you start to write a
program, so they aren't encountered at the design stage.

A {   

:   
 
  
*
 
     
  { 
    

 



      
 

{ 
 
 
 


    
  V

   
  

a  V
    


 



 

   

$ echo "customerID = $customerID"


customerID = 411
$
: 
 V
 
    
   
 
 


 
    

read.customer.info () {
> echo $*
> new_entry[0]=$1
> new_entry[1]=$2
> new_entry[2]=$3
> new_entry[3]=$4
> }
$

{ 
 
V
  
 (
     V

  
  
  



while (($count<$total))
do
name=new_entry[0]
touch "$name _data"
count+=1
echo "iteration $count, name is $name"
done

Ú
  V
   
   5  * 
    
   
 
  
      

{ 
   
        

  

while $count<$total
do
name=new_entry[0]
touch "$name _data"
count+=1
 echo "iteration $count, name is $name"
done

a 

 


 


  

{


 

       

 
 


Î 


  
        
  *
 
  4

5 6

- |
 

 
 


8 |
 
 
  

9 |
 
 



/ |
 
    

¦ 

  
   
   
 
 

 




{  

  


× $
×  (
× 

$
{ $



   
 
       
 { 
    
 
 


      


 
 (
{  (



    
   {  
 
 *
   
 


    

 
   
 
 
   


 
     
 

{ 



     

     


 !       
  2 { 
    




  
     *
   
      
 


 
  
  

a  
  
 


command signal

 
  $
       

  

  

$ trap showvars DEBUG


 
        

  
 


 


    
      
 
     
  

{ 



 
   
     


$ trap - DEBUG

 
   (
            

 ( 
{      


 
 
 




     


 
   
 

$ trap exitmsg EXIT

Î 

  


 
  V


5 6

- a 
  V
     
     
8 a 
 V
 



9 a  V
  


      

/ a     V
   

¦ 

{ V
     
 


 *
 
      a     V
  


Option 1 is correct. The  command simply prints any arguments to standard
output. It doesn't affect control flow, so is useful for debugging programs.

Option 2 is incorrect. The  command will print the value of any variable passed
to it as an argument, but it can't be used to rename variables.

Option 3 is correct. The  command can't modify the value of variables passed to
it in arguments, so it is useful for monitoring variable values in order to debug
programs.

Option 4 is correct. Any line in a shell script that is preceded by a  is treated as a


comment, including lines containing the  command.

Î 

a 
 
  

 
 
  
 a 
 
  
       
  

  
      
4
5 6

- $
8 
9  (

¦ 

a   ( 


      
 
 

Option 1 is incorrect. The DEB G signal is used to create a trap that executes code
after every command in the scripts is executed.

Option 2 is incorrect. The ERR signal is used to create a trap that executes code after
every error command, whether or not the error causes the program to exit.

Option 3 is correct. The EIT command is used to create a trap that executes code ±
in this case code that removes temporary files ± when a program terminates. The
specified code will be executed even if the program terminates unexpectedly.

X ¦      · 

{ 
   
   
      

{       


  6

× V
× ’ 
× V

V
{ V  
   

      

{ 
  
    
     




  
’ 
{  ’    
 

      

  { 

   


             

 
  
V
{ V   

  
  
 * 
  


 


    
  {  
 
   

     
 

 
{ 
 V   
   
 
{ V
 !  

 ½! 
 
    

  

 
 { 
    

    
  9    

 

$ ((res = 36/4 + $i))


+ let res = 36/4 + 3
$



You can customize the r prompt using the S environment variable.

a       


     {   
  ’   

$ set -o verbose

a 
  
     a       
    {   
 V  

$ set -x

{ 
       
{    
  ’   

$ set +o verbose



You can't unset the  option because it prevents the  + command from
executing.

Î 

       


      

  
  4

5 6

- V
8 ’ 
9 V

¦ 
{  ’    
      

    

{      


   
      

   


  


   

   


   

× 

       
×

         
×  


 
   
 
×

   
 
   

a 
         
  : 

 7
    7
 

{  7
  
   
   7
  
  
’   

$ bash --debugger add_pkg_files

Î 

    
        

 
  
 4

5 6

- V
8 ’ 
9 V

¦ 

{ V  
        

 
  
 

Option 1 is incorrect. The  option reads commands without executing them.
It's useful for discovering syntax errors.

Option 2 is incorrect. The r  option causes input to be displayed as it is read.


It's useful for verifying input.

Option 3 is correct. The r option displays each command as it is executed and
is the most appropriate option for general debugging.
Î 

  


 
    

5 6

-    


   
  
8 a 

    


   
 
9 a 

     


 
    
/ a 

    
   

¦ 

   


   
  a 
  

   
 


 
    

Option 1 is correct. When you execute a debugging script you supply the target script
as a parameter. The debugging code is appended to the code of the target script.

Option 2 is incorrect. A debugging script may help you locate the source of a logical
error, but it won't correct it.

Option 3 is correct. A debugging script can be used to set traps that print useful data
± such as the values of variables ± when a program exits unexpectedly.

Option 4 is correct. You can use a debugging script to set shell options ± such as the
r option ± that facilitate debugging.

. /    

 *   


  
3       
 

     
 


: 

   


  *
  
2  
 
8/

Î 


    
     
 
 

4

5 6

- (    


8  
  

9  



/ Õ
   

¦ 

  *    


  

  
 
      
   

    

{ 
 
 
  



      
 
 

 

  

    *   
 3 
 


read.date () {
> echo "Enter month:"
> read month
> if ((month<0)) | ((month>12))
> echo "Invalid month "
> exit
> fi

 

        3 


a 

 
    
        
    
   
  {       
    


 
   

  
  

a 

  V
 

   
 
 



      *  a 

 
  




  
    

a 
     
  { 
      
 
   a 

        

  
 

     

     
 
 
 
 


{     

){  )

)    )

) {     )


)A {   )

)X ¦      · )

). /    )

) )

@   F8GG9| |    


| | 
 | |   


  


| |    |

 
    
     


        

       

! +    c
  
¦     

{



 
   
  
   
   

 

 
 


    
  
  



 

a *  
  
 


   
 
   
   *

    
    * 

 
å  
 *    
  
 




a 
        
 

      

    
  
 
 
 

{ 

    

 Õ         6



 /usr/local/bin/ksh
DirPath="/home/shared/"
Exist=0

while [[ $Exist -ne 0 ]]


do
{ 

    

echo
"***************************************************
Welcome, $USER
Please type the Directory
Then press Enter:"
read DirName
if [[ -d $DirPath]]; then
Exist=1
echo
"***************************************************
DIRECTORY EXISTS, Please Enter Another
Directory"
else
Exist=0
fi
done

clear
mkdir -m 777 $DirPath$DirName
echo "The $DirName directory has been created in
$DirPath. Are you happy with this?"
read -p "[y/n]" BOOL1
clear
if [ $BOOL1 = n ]
then
rmdir $DirPathDirName
echo "$DirName has been removed"
exit
else
touch $DirPath$DirName/status$DirName
chmod 666 $DirPath$DirName/status$DirName
if

Õ    


  

         


{     

){  )

) )

))

@   F8GGK| |    


| | 
 | |   


  


| |    |

 
    
     


        

You might also like