Prev Next

DataStructures / Shell Scripting Interview Questions

Could not find what you were looking for? send us the question and we would be happy to answer your question.

1. What is a shell?

Shell is an interface between the user and the kernel. Even though there can be only one kernel; a system can have many shells running simultaneously. So, whenever a user enters a command through the keyboard, the shell communicates with the kernel to execute it and then displays the output to the user.

2. What is Shell Scripting?

Shell Scripting is an open-source computer program designed to be run by the Unix/Linux shell. Shell Scripting is a program to write a series of commands for the shell to execute. It can combine lengthy and repetitive sequences of commands into a single and simple script that can be stored and executed anytime which, reduces programming efforts.

3. Different types of commonly used shells on a typical Linux system.

Different shells include csh, ksh, bash (Bourne Again Shell), and Bourne. The most commonly used shell is "Bash" .

4. What is a Symlink?

A symlink or a Symbolic Link is simply enough a shortcut to another file. It is a file that points to another file.To create a symbolic link you use the following command:

ln -s target_path link_path

For example, the below command creates a symlink MY_DIR for the actual directory my_folder.

ln -s ~/Desktop/my_folder ~/Desktop/MY_DIR
5. Why is shell scripting required?
  • Shell helps in doing work that is repetitive in nature. For example: When executing a bunch of commands, shells can take all these commands directly from a stored file and execute them, instead of writing them every time.
  • Used to run routine backups/tasks by admins.
  • They are easier to write and debug than other programming languages like PERL, and PYTHON.
  • We can transfer the shell script to other UNIX and similar operating systems and execute it.
  • Shell scripts are also used to monitor systems regularly.
6. What is a Shell Variable?

− A shell variable is a special variable that is set by the shell and is required by the shell in order to function correctly. Some of these variables are environment variables whereas others are local variables.

#!/bin/sh

NAME="Javapedia.net"
unset NAME
echo $NAME
7. Mention few limitations of shell scripting?
  • There may be errors in shell scripting that prove to be quite costly.
  • The programs in shell script are quite slow while executing and a new process is required for every shell command executed.
  • Different platforms in shell scripting may also have compatibility problems.
  • Large, complex tasks aren't well suited to it.
  • Contrary to other scripting languages, shell scripting provides a minimal data structure.
  • Every time a shell command is executed, a new process is launched.

8. What is the extension of Shell program files?

Shell programs are stored in files with .sh extensions. For example. CleanupScript.sh.

9. What are the different types of shells?

Shells are divided into two categories:

Bourne shell: The $ character is the default prompt when using a Bourne-type shell.

C shell: The % character is the default prompt.

There 2 sub categories of Bourne shell:

Bourne Again shell (BASH): Bash or Bourne Again Shell is the similar shell to Bourne or .sh in Unix. Bash shell was developed by the Freeware Software and it is written and licensed under the GNU organization. It's free and open-source. It is an SH-compatible shell, with improved programming and interactive features over SH. Some useful features of Bash shell are tab completion and setting a prompt to display the current directory.

Korn shell (KSH): Korn Shell or KSH was developed by a person named David Korn, which attempts to integrate the features of other shells like C shell, Bourne Shell, etc. It has associative arrays and handles the loop syntax better than Bash. It is basically an improved version of Bourne shell. It provides much better performance while dealing with execution of scripts and commands.

The C-Shell is subdivided into the following categories:

C shell (CSH): CSH is almost like C itself since it uses the shell syntax of the C programming language. In most cases, a command is executed either interactively from a terminal keyboard or from a file.

TENEX/TOPS C shell (TCSH): Tcsh is an enhanced version of the csh. It behaves exactly like csh but includes some additional utilities such as command line editing and filename/command completion. Tcsh is a great shell for those who are lazy with typing and/or have trouble remembering Unix commands.

10. Differences between CSH and BASH.

BASHCSH
Bourne Again Shell starts with ';'.C-Shell commands begin with a '#'.
Bash is considered as non- interactive.CSH stands for the interactive terminal.
Easy to understand.The difficulty level is intermediate.
«
»
Application Security Interview Questions

Comments & Discussions