Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Linux Shell Scripting Interview Question     - Ubuntu Control Panel to resolve network-manager icon display issue (Linux)

- About Nginx 7 (Server)

- The compiler installed Kaldi under Ubuntu 12.04 (Linux)

- Oracle Standby Redo Log experiment (Database)

- How to Install 3.16.7 CKT2 kernel in Ubuntu 14.10, Ubuntu 14.04 and its derivative versions (Linux)

- Linux NFS service fixed ports and firewall configuration (Linux)

- MySQL & NoSQL - Memcached widget (Database)

- Try debugfs restore the deleted files ext3 file system (Linux)

- AngularJS asynchronous service testing and Mocking (Programming)

- The virtual memory (Linux)

- Shell scripts to copy all directories under the current directory of a certain type of file to the same directory (Linux)

- Linux system performance tuning of Analysis (Linux)

- Give your photos Instagram style filters plus program in ubuntu (Linux)

- UNIX and class UNIX system security check notes (Linux)

- CentOS 7.1 install NTFS-3G (Linux)

- Swift rewrite initialize method of navigation controller class (Programming)

- IIS virtual host of safety knowledge (Linux)

- Linux iostat command example explanation (Linux)

- Linux use glibc2 library and crypt () function to generate the user password (Programming)

- Linux SVN account password to save your settings (Linux)

  Linux Shell Scripting Interview Question
  Add Date : 2018-11-21      
  Q: What is 1 Shell script is that it is necessary?

A: A Shell script is a text file that contains one or more commands. As a system administrator, we often need to use multiple commands to complete a task, we can add all of these commands in a text file (Shell scripts) to perform these daily tasks.

Q: 2 What is the default login shell, how to change the designation of the user's login shell

A: Linux operating system, "/ bin / bash" is the default login shell, is assigned when creating the user. Using the chsh command to change the default shell. Example is shown below:

# Chsh < user name> -s < new shell>
# Chsh linuxtechi -s / bin / sh
Q: 3 What types of variables can be used in shell scripts?

A: In the shell script, we can use two types of variables:

System-defined variables
User-defined variables
System variables are created by the system, the system itself. These variables are usually consists of uppercase letters, you can "set" command.

User variables by the system user to generate and define the value of a variable through the command "echo $ " Show.

Q: 4 How to standard output and error redirected to the same location at the same time?

A: There are two ways to achieve:

method one:

2> & 1 (such as # ls / usr / share / doc> out.txt 2> & 1)
Method two:

&> (Such as # ls / usr / share / doc &> out.txt)
Q: 5 shell script "if" syntax how to nest?

A: The basic syntax is as follows:

if [condition]
Command 1
Command 2
... ..
if [condition]
Command 1
Command 2
Command 1
Command 2
... ..
Q: 6 shell script "? $" Mark what is the use? ?

A: Write a shell script, if you want to check whether the previous command is successful, if used in the criteria can check the status before the end of a command "$?." Simple examples are as follows:

root @ localhost: ~ # ls / usr / bin / shar
/ Usr / bin / shar
root @ localhost: ~ # echo $?
If the end state is 0, indicating that the previous command executed successfully.

root @ localhost: ~ # ls / usr / bin / share
ls: can not access / usr / bin / share: No such file or directory
root @ localhost: ~ # echo $?
If the end state is not 0, command execution failed.

Q: 7 in shell scripts how to compare two numbers?

A: Use the test command (-gt, etc.) in the if-then to compare the two figures, examples are as follows:

#! / Bin / bash
x = 10
y = 20
if [$ x -gt $ y]
echo "x is greater than y"
echo "y is greater than x"
Q: 8 shell script commands on the break?

A: break command uses a simple implementation is to exit the loop. We can use the command to break out of the loop in the while and until loops.

Q: 9 shell script commands continue in the role?

A: continue command is different from the break command, only out of the current loop iteration, rather than the entire cycle. continue commands are often useful, for example, an error, but we still want to continue a cycle of time.

Q: 10 Tell me the syntax shell script Case statement?

A: The basic syntax is as follows:

Variables in case
Value 1)
Command 1
Command 2
... ..
Last Command
Value 2)
Command 1
Command 2
Last Command
Q: 11 shell script while loop syntax?

A: As for loop, while loop is repeated as long as the conditions established its command block. Unlike for loop, while loop iteration will continue until its condition is not true. Basic Grammar:

while [condition]
Q: 12 How to make the script executable?

A: Use the chmod command to make the script executable. Examples are:

# Chmod a + x myscript.sh
Q: 13 "! # / Bin / bash" role?

Answer:! # / Bin / bash is the first line of the shell script, called the release with (shebang) line. Here the # symbol, called hash, and! Is called the bang. It means that command / bin / bash to execute.

Q: 14 shell script for loop syntax?

A: The basic syntax for loop:

for a list of variables in loop
Command 1
Command 2
Last Command
Q: 15 How to debug a shell script?

A: Use the '-x' (sh -x myscript.sh) can debug shell scripts. Another way is to use '-nv' parameters (sh -nv myscript.sh).

Q: 16 shell script how to compare strings?

A: test command can be used to compare strings. Command to compare the test by comparing each character in the string.

Q: What specific variable 17 Bourne shell (bash) have?

A: The following table lists the special variable for the Bourne shell command line settings.

Built-in variables


$ 0

Command line script name

$ 1

The first command line argument

$ 2

The second command line argument

... ..


$ 9

The ninth command line arguments

$ #

Number of command-line arguments

$ *

All command line arguments, separated by spaces

Q: 18 How to test files in a shell script?

Q: 18 in the shell script, how to test the file?

A: test command can be used to test the file. Basic usage of the following table:



-d filename

If the file exists and is a directory, returns true

-e filename

If the file exists, returns true

-f filename

If the file exists and is a regular file, returns true

-r filename

If the file exists and is readable, returns true

-s filename

If the file exists and is not empty, returns true

-w filename

If the file exists and is writable, the true

-x filename

If the file exists and can be executed, returns true

Q: 19 in the shell script, how to write a note?

A: Notes can be used to describe a script can do and how it works. Each line comments begin with #. Examples are:

#! / Bin / bash
# This is a command
echo "I am logged inas $ USER"
Q: 20 How to make shell script to get input from the terminal?

A: read command to read data from the terminal (using the keypad). read command to get user input and set in the variable you given. Examples are:

# Vi /tmp/test.sh
#! / Bin / bash
echo 'Please enter your name'
read name
echo "MyNameis $ name"
# ./test.sh
Please enter your name
Q: 21 How do you cancel or cancel variable variable assignment?

Answer: "unset" command to remove the variable or cancel the variable assignment. The syntax is as follows:

# Unset < variable name>
Q: 22 How to perform arithmetic operations?

A: There are two ways to perform arithmetic operations:

1. Use the expr command (# expr 5 + 2) 2. by a dollar sign and brackets ($ [expression]), for example: test = $ [16 + 4]; test = $ [16 + 4]

Q: 23 do-while statement is the basic format?

A: do-while statement is similar to the while statement, but to execute the command before checking the condition statement (LCTT Annotation: means for performing at least once). Below is do-while statement syntax

} While (condition)
Q: 24 How-defined functions in a shell script it?

A: The function is to have the name of the code block. When we define a block of code, we can call the function name in our script, the block will be executed. Example is shown below:

$ Diskusage () {df -h;}
Annotation: The following is a shell function syntax I give, not original
[Function] function name [()]
Q: 25 How to use the BC (bash calculator) in the shell script?

A: Use the following format, using bc in shell scripts:

variable = `echo" options; expression "| bc`
- Arduino UNO simulation development environment set up and run simulation (Linux)
- ARM assembler instruction debugging method (Programming)
- Linux Log File Browser --logrotate (Linux)
- Linux system monitoring tool set cpu (Linux)
- Linux smart small switch rfkill (Linux)
- How to build Mono 3.4.0 / 3.4.1 on Windows (Linux)
- Enterprise Hadoop cluster architecture - DNS installation (Server)
- LinSSID: a graphical Wi-Fi scanner under Linux (Linux)
- Linux common network tools: Scan routing of mtr (Linux)
- PSUADE installation under Linux (Linux)
- Linux find command to find files (Linux)
- React Native (Programming)
- CentOS 6 kernel upgrade to Kernel 3.x (Linux)
- CentOS 6.5 Telnet SecureCRT use management tools (Linux)
- SolrCloud-5.2.1 cluster deployment and testing (Server)
- To control based on IP address routing policy under Linux (Linux)
- CentOS 7 Add yum source (Linux)
- Java Prototype Pattern (Programming)
- Install the latest Pinta graphics editing software on Ubuntu 14.04 (Linux)
- Linux crontab use (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.