Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

UNIX Shell Programming Interview Questions You'll Most Likely Be Asked
UNIX Shell Programming Interview Questions You'll Most Likely Be Asked
UNIX Shell Programming Interview Questions You'll Most Likely Be Asked
Ebook173 pages2 hours

UNIX Shell Programming Interview Questions You'll Most Likely Be Asked

Rating: 0 out of 5 stars

()

Read preview

About this ebook

  • 276 UNIX Shell Programming Interview Questions
  • 76 HR Interview Questions 
  • Real life scenario based questions
  • Strategies to respond to interview questions
  • 2 Aptitude Tests

UNIX Shell Pro

LanguageEnglish
Release dateAug 21, 2018
ISBN9781949395037
UNIX Shell Programming Interview Questions You'll Most Likely Be Asked

Read more from Vibrant Publishers

Related to UNIX Shell Programming Interview Questions You'll Most Likely Be Asked

Titles in the series (33)

View More

Related ebooks

System Administration For You

View More

Related articles

Reviews for UNIX Shell Programming Interview Questions You'll Most Likely Be Asked

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    UNIX Shell Programming Interview Questions You'll Most Likely Be Asked - Vibrant Publishers

    UNIX Shell Programming Interview Questions

    You'll Most Likely Be Asked

    Job Interview Questions Series

    www.vibrantpublishers.com

    *****

    UNIX Shell Programming Interview Questions You'll Most Likely Be Asked

    Copyright 2021, By Vibrant Publishers, USA. All rights reserved. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior permission of the publisher.

    This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The Author or the Publisher will not be liable for any damages caused or alleged to be caused either directly or indirectly by this book.

    Vibrant Publishers books are available at special quantity discount for sales promotions, or for use in corporate training programs. For more information please write to bulkorders@vibrantpublishers.com

    Please email feedback/corrections (technical, grammatical or spelling) to spellerrors@vibrantpublishers.com

    To access the complete catalogue of Vibrant Publishers, visit www.vibrantpublishers.com

    *****

    Table of Contents

    1. C Shell - Beginner

    2. C Shell – Intermediate

    3. C Shell – Advanced

    4. Bash - Beginner

    5. Bash - Intermediate

    6. Bash - Advanced

    7. Basics

    8. Commands

    9. Variables and Arrays

    10. Special Shell Variables

    11. Operators and Shell Substitutions

    HR Interview Questions

    INDEX

    *****

    UNIX Shell Programming

    Interview Questions

    Review these typical interview questions and think about how you would answer them. Read the answers listed; you will find best possible answers along with strategies and suggestions.

    *****

    C Shell - Beginner

    1: What must you do before you are able to run your new script for the first time by its name or with an alias?

    Answer:

    You must make it executable, that is to execute the command:

    chmod +x scriptname

    2: The following command is included in the .login script of a user:

    alias whois ´grep \!ˆ /etc/passwd´

    What will be the output, when the user issues the following?

    who is guru

    Answer:

    If there is a defined user account named "guru", or the string guru is contained elsewhere in /etc/passwd file, then the output will be the entry which contains the string "guru", otherwise, it will be an empty line.

    3: If the condition If (-r filename)fails (returns false), what are the possible reasons?

    Answer:

    The possible reasons are:

    a) filename is not readable by the owner of the process

    b) filename does not exist

    4: Which is the difference between the next two statements?

    set var =99

    @ var = 99

    Answer:

    Using the typical assignment form (set ...), the value assigned in var is the string 99. Using the @, the value is the integer 99.

    5: Given the code snippet:

    @ n = 5

    while ($n)

    # actions

    ...

    end

    What actions should be performed inside the loop, in order to get out of this loop?

    Answer:

    Any command that changes the value of variable n, for it to become 0 sometime. E.g., @ n—

    6: What will the output of the following commands be? Explain.

    set names =(Kathrin Chris Jacob)

    shift names

    echo $#names

    Answer:

    The output will be 2.

    shift command gets rid of the first element of the array names. So, the echo command will display 2 as the number of elements of the array.

    7: What does the command rehash do?

    Answer:

    Rehash recomputes the internal hash table for the PATH variable. If the new command resides in a directory not listed in PATH, add this directory to PATH, and then use rehash.

    8: How could you ensure that a script will be run in csh?

    Answer:

    The first line of the script could be used to define the shell you want to use, as follows:

    #!/bin/csh

    This is sufficient to run the script in csh.

    9: Given that script1 is an executable C shell script situated in directory /home/myhomedir/project1/data/dir1, use three ways to run it, explaining the pros and cons.

    Answer:

    a) cd/home/myhomedir/project1/data/dir1/script1 (You should first cd to the directory path)

    b) /home/myhomedir/project1/data/dir1/script1 (You should include the absolute directory path)

    c) script1 (shortest form, but it works only if the directory path is added to the PATH environment variable of the user)

    10: What will be the value of the sixrem variable, after executing this command?

    @ sixrem = $data[2] % 6

    Answer:

    The expression divides the value of second element of the data array by 6 and assigns the remainder of the division to the sixrem variable.

    11: Name two ways to obtain the length of a string, giving a simple example for each one.

    Answer:

    The two ways to obtain the length of a string are:

    a) Using the wc command:

    set string = any string

    @ ln = `echo $string | wc -c` -1

    b) Using the awk function length:

    set string = any string

    set ln = `echo $string | awk '{print length($0)}'`

    12: Create a script that displays a list of regular files from the current directory.

    Answer:

    #!/bin/csh -f

    foreach i (*)

    if( -f $i ) then

    print $i

    endif

    end

    13: Describe in short, the word-completion feature of the tcsh shell.

    Answer:

    If you want word completion to work, whether on commands or filenames, you just need to type the beginning of the word and press the Tab key. The Shell will substitute the unfinished word with a complete one which is available in the input buffer and also adds a / to its end if it’s a directory and a space if it’s a word. The shell will check the buffer to identify whether the completed word is a word or a command, variable or filename. The buffer considers the first word in it and the words following {‘|’, ‘|&’, ‘;’, ‘&&’, ‘||’} as a command. If the word starts with a $ it’s a variable and everything else is a filename. If there’s an empty line, it is completed as a filename.

    14: In tcsh, how are the remaining choices (if any) listed whenever the word completion fails?

    Answer:

    The remaining choices (if any), are listed only if the shell variable autolist is set.

    15: In tcsh, how do you disable filename substitution?

    Answer:

    noglob shell variable can be set to disable the filename substitution feature.

    16: Compare the sched tcsh built-in command with the UNIX/Linux at command.

    Answer:

    These commands are similar but not the same. sched command runs directly from the shell, so it has access to shell variables and settings at command can run a scheduled command at exactly the specified time.

    17: Schedule a prompt change at 10:55 as a reminder for an oncoming event.

    Answer:

    sched 10:55 set prompt = 'It\'s time for the important meeting: >'

    18: What is the impact of -f option in the first line of a csh script?

    (#!/bin/csh

    versus

    #!/bin/csh -f)

    Answer:

    When you add the -f option to csh, the shell will skip loading the startup files .cshrc and resources. It will also skip the hashing process. The shell will load quicker because of that.

    19: How can you start a job in the background, and then terminate your login session, without terminating the background job?

    Answer:

    We can start a job in the background and then terminate our login session, without terminating the background job using no hangup command, nohup:

    nohup command > output_file &

    20: Which is the difference between

    echo c{1,4,2,5,1}

    and

    echo [c]{1,4,2,5,1}?

    Answer:

    The first echo will display c1 c4 c2 c5 c1, while the second displays only c1.

    21: Display the first and last arguments of a script, regardless of the number of arguments, and without a loop.

    Answer:

    my_var3 = $#argv

    echomy_var1: $argv[$1]

    echomy_last_var: $argv[$my_var3]

    22: How will you set the ‘search path’ in csv?

    Answer:

    Search path in csv can be set as follows:

    a) setenv PATH/myfolder1 /bin: /myfolder2 /myfile3

    b) using list

    set path =( /myfolder1 /bin /myfolder2 /myfile3 )

    23: Create a tar archive into /home/user1/myarch.tar, including all files ending in .c, .h, .l, .y,.o and .cc and also the Makefile from two directories, ~/dir1 and ~/dir2.

    Answer:

    tar cvf /home/user1/myarch.tar ~/{dir1,dir2}/{Makefile,*.{c,h,l,o,y,cc}}

    or

    tar cvf /home/user1/myarch.tar ~/dir1/Makefile ~/dir1/*.[chloy] ~/dir1/*.cc ~/dir2/Makefile ~/dir2/*.[chloy] ~/dir2/*.cc

    24: Your script must be executed with exactly two arguments, otherwise would be terminated. Write a code to implement these checks.

    Answer:

    if ($#argv <> 2) then

    echo Usage: $0 arg1 arg2

    echo "You must give exactly two

    Enjoying the preview?
    Page 1 of 1