10 Useful ‘Interview Questions and Answers’ on Linux Shell Scripting

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

24 Responses

  1. jagan says:

    I need to execute a script on remote as a sudo user or root user from my local VM. It is not password less login. we need to pass password thorugh command line.

    #!/bin/bash
    sshpass -p “xxxx” ssh -o StrictHostKeyChecking=no [email protected] <<EOF
    echo "password" | 'sudo su -'
    sh script.sh
    EOF
    Note : there is no sshpass in remote server and we cannot install it for security reason.

    I am able to login to remote user as user but i can't login as a sudo user , Please help me how to achieve this. i have seen many quires but none one helped me

    -Thanks Jagan

    • Ravi Saive says:

      @Jagan,

      Have you enabled sudo privileges to user you trying to login into the server? if not, first add users to sudoers file with the help of visudo command.

  2. Ranjan says:

    Hey I want to what are the production support issues we got in real time please any one could give few examples

  3. Sunny Desouza says:

    Hello tecmint,

    I need a solution .for the below

    Write a Shell program to print the numbers in the following format:
    Use While or Until loop for the following program

    1  2  3  4
    2  3  4  5
    3  4  5  6
    4  5  6  7
    5  6  7  8
    6  7  8  9
    

    My Written Script in Until Loop, kindly correct where i have made a mistake

    #!/bin/bash
    w=1
    until [ $w -le 9 ] ;  do
         until [ $w -eq  4 ] ; do
      w=`expr $w + 1`
      echo "$w"
       done
    echo "$w"
    done
    

    Regards,
    Sunny

    • Siddarth says:

      i=1
      while [ $i -lt 7 ]
      do
      m=`echo $i`
      for n in 1 2 3 4
      do
      printf “$i”
      i=`expr $i + 1`
      done
      i=`expr $m + 1`
      printf “\n”
      done

      • strangelove says:

        I’m a bit late to the party, but something more concise might be:

        i=1
        until [ $i -gt 6 ];
        do
          printf "%d %d %d %d\n" $i $((i+1)) $((i+2)) $((i+3))
          : $((i++))
        done
        
  4. Varun says:

    Point 6 is little mis-infomative.

    — “Zombie : A Process is said to be ‘Zombie’ if it has stopped but still active in process table.” —

    Technically a process cannot be active after it have been stopped, Actually Zombie is a process when parent process is killed/stopped but the child process still exists, That child process is known as Zombie process.

  5. Rodney Ricks says:

    No, the ‘ls’ command cannot be substituted by ‘echo’ command.

    The echo command prints strings on the command line to standard output.

    When you run ‘echo *’, you are not running an ls command.

    What happens is that the shell expands the ‘*’ regular expression, replacing it with the list of files and directories in the current working directory.

    The echo command merely prints the result as a list of strings.

    The ls command lists the files or directories listed on the command line.

    You can more easily see the difference when you run the commands in a directory with no files or subdirectories in it that don’t being with a ‘.’.

  6. Nagy Huho says:

    Since when ‘ls’ is used to print the content of a file?

    • Avishek Kumar says:

      not as fruitful as ls in all aspect but for simply printing the contents of a directory you may use

      $ echo * and it will print the contents, but again not as versatile as ‘ls’

  7. red says:

    Thanks a lot, very usefull.
    for the sticky bit question, where should i create the directory ?
    I’ve created a directory in my home /home/red
    i’ve created as you said a directory inside as you told, but when i log as another user and try to edit the sticky directory, there is a permission problem!!
    thanks

    • Avishek Kumar says:

      Follow every step as directed
      # mkdir dir_xyz
      # chmod g+wx dir_xyz
      # chmod +t dir_xyz

      And it should work.

  8. vamsi says:

    clarification regarding
    How will you abort a shell script before it is successfully executed?
    for the above question exit 1[any non zero will work other than zero].please correct me if i am wrong?

  9. shri says:

    Thank you :-)

  10. rupesh kolatwar says:

    Hi avishek

    How can we select all the text in one shot while working in vi editor
    i frequently need to copy & past text to multiple files

    Regards
    Rupesh K

Leave a Reply to Sunny Desouza Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.