Shell Interview Topics

Source: Internet
Author: User
Tags egrep

1. What role does Eval have in the shell? Could you give me an example?

Role:

#!/bin/bash

Aa=h1

Bb=h2

var= (AA bb)

For VAS in ${var[@]}

Do

Echo $vas

Eval Var_temp=\$${vas}

Echo $var _temp

Done


2. What is the role of dirname? Could you give me an example?

Function: Gets the current script path

Example:

#!/bin/bash

CD ' DirName $ '

Pwd;ls


3, Ssh-o stricthostkeychecking=no-o connecttimeout=60 respectively mean?

SSH does not need to enter the key check, and then 60 seconds is the time-out


4, say the-n-z-d-f-e-r-w-x-L!-z in the shell respectively what meaning? -N and-Z give an example to illustrate

-N non-NULL is True

-Z string is NULL for true

-D is a directory and exists as true

-F is a normal file and exists as true

-E exists as true

-R readable as True

-W can be written as true

-X Executable for True

-L is a link to true

!-z is not empty

1)-n Example:

Javaapp= ($ (PS aux | grep "java" | grep "/app/guaji"))

If [-N ' ${javaapp[0]} "];then

echo-e "\033[1;31m script exit \033[0m"

Exit 1

Fi

2)-z Example:

ssh=$ (ssh-o stricthostkeychecking=no "ls/")

If [-Z ' $ssh ']];then

ECHO-E "\033[1;31m \033[5m remote host ($) cannot connect, the script exits. \033[0m "

Exit 1

Fi


5, the regular expression "|", "\ n", "\ r", "\ T" respectively mean what

The meaning of the expression or

\ n indicates a newline, starting with the current offset down the line

\ r Enter to move the current position to the beginning of the bank


6, write out the two methods of acquiring public network IP

Ifconfig | Grep-po "(? <=ADDR:). * (? =bcast)" | egrep-v ' ^192.168|^172.1[6-9].| ^172.2[0-9].| ^172.3[0-1].| ^10.| ^127. '

/sbin/ifconfig | Awk-f ' [:]+ '/inet addr:/ {print $4} ' | Egrep-v ' ^192.168|^172.1[6-9].| ^172.2[0-9].| ^172.3[0-1].| ^10.| ^127. '


7. What does $$ mean?

Gets the process name of the current execution script


8. What does local in the function mean? Give a script example to illustrate

Local variables in the script, variables that exist in the script function (functions) are called local variables, and are declared locally so that they are valid only within the scope of the function.

To prevent a variable from being named in the letter and the variable name in the variable external program causes a program exception, here is a script example:

#!/bin/sh

A () {

Local S=1

Echo $s

}

B () {

s=2

Echo $s

}

S=0

A

Echo $s

B

Echo $s


9, [email protected] and $* difference

[email protected] treats each parameter of the command line as a separate string, equivalent to "$", "$", "$"

$* treats all command-line arguments as a single string, equivalent to "$1$2$3"


10. What is the role of dirname and basename?

DirName Get Script path name

BaseName get the name of the foot

$ $ get Script path and pin name

11. Remove the 3306 port number

netstat-tlnp| grep 3306 | awk ' [:]+ ' {print $} ' #[:]+ with a space and a dot delimiter, which has one or more


12. What is the meaning of single and double quotation marks and no-plus numbers in the shell?

Single quotation mark: can be said to be WYSIWYG, will be the contents of the quotation marks as output

Double quotation marks: The contents of the double quotation marks, if there are commands, variables, etc., will first parse the variables, commands, and then output the final content to

No quotation marks: the output of the content, the string containing the space as a whole output, if the contents of the command, variables, etc., will first parse the variables, commands to the results,

Then output the content, if the string with a space and other special characters, it can not complete the output, need to add double quotation marks, general continuous string, the number

The path can be without any quotation marks, but it is best to use double quotes instead of


13. What does echo-n mean? Give a script example to show his function

-N No Line break

#!/bin/bash

. /etc/init.d/functions

echo "---------wait while we are checking-------------"

Echo-n "After 6 seconds to perform the operation."

For ((i=0;i<6;i++))

Do

Echo-n "."; Sleep 2

#[$i-eq 3] && break

Done

Echo

Action "Test Success"/bin/true


14, echo-e "\ n" | Nohup ping www.baidu.com > FileName 2>&1 & what does it mean by-e and "\ n" here?

-E is a parameter that represents what is entered later that contains a special bead character that needs to be added

\ n represents a newline.

15, there are 1-9 of the number, echo output 1-9 of the number, shielding 0-5 of the digital re-output

echo ' 1234567890 ' | Sed ' s/[0-5]//g '


16, use Nohup to put a script in the background to run

Nohup sh test.sh > FileName 2>&1 &

17, with SEQ Print 10 separated by a space, with SEQ hard to print 10 to 1

Seq-s "" 10

Seq 10-1 1


18, Curl-i-S www.baidu.com | head-1 | What does the-I and-s in wc-l mean?

-s silent or quiet mode. No progress meter or error message is displayed. Mute the Curl

-I only read HTTP headers! HTTP Server function command head this is used to get

--connetct-timeout 2 2 seconds Connection timeout

19, Wget-t 10-c-Q--spider www.baidu.com These parameters represent what meaning?

-T Timeout 10 less

-C Breakpoint continued to pass

-Q to mask the meaning of his printout when executing the command, execute the command without any content.

--spider wget command plus spider parameter does not download anything, the spider's primary role is to test the download link.

Tries

20, the production environment commonly used to monitor the Web method is what kind

Monitoring with wget or Curl method


21, the production environment write foot This newspaper wrong on the order of e-mail is how

Mail-s "Uname-n's httpd status is on" [email protected] < $logfile


22. Renaming files

MV $file 1linux-' echo $file | Cut-d "-"-f2 ' #详情看老男孩shell第三天文档, dynamic variable, static

LS *.jpg | Awk-f ' _finished ' {print "MV" "$" "$". jpg "} ' | Bash


23. View all folders in the current directory

Ls-f | grep/


24, view 192.168.1.0/24 network segment of the host there is no online


25. What does the NF in awk mean?

NF stands for the end meaning


This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1786895

Shell Interview Topics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.