In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the topics of Linux Shell script interview". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
What is the QRV 1 Shell script and is it necessary?
A: an Shell script is a text file that contains one or more commands. As system administrators, we often need to use multiple commands to complete a task, and we can add all these commands in a text file (Shell script) to complete these daily tasks.
What is the default login shell and how to change the login shell of a specified user
Answer: in the Linux operating system, "/ bin/bash" is the default login to shell and is assigned when the user is created. The default shell can be changed using the chsh command. The example is as follows:
# chsh-s # chsh linuxtechi-s / bin/shQ:3 what types of variables can be used in shell scripts?
A: in shell scripts, we can use two types of variables:
System definition variable
User-defined variable
System variables are created by the system itself. These variables are usually made up of uppercase letters and can be viewed with the "set" command.
User variables are generated and defined by the system user, and their values can be viewed with the command "echo $".
How to redirect standard output and error output to the same location at the same time?
A: there are two ways to do this:
Method 1:
2 > & 1 (# ls / usr/share/doc > out.txt 2 > & 1)
Method 2:
& > (# ls / usr/share/doc & > out.txt)
How is the "if" syntax nested in the QRZ 5 shell script?
A: the basic syntax is as follows:
If [Condition] thencommand1command2... .. elseif [condition] thencommand1command2... .elsecommand1command2... .. fifi
"$?" in QRV 6 shell script What is the purpose of marking? ?
When writing a shell script, if you want to check whether the previous command was executed successfully, use "$?" in the if condition. You can check the end status of the previous command. Simple examples are as follows:
Root@localhost:~# ls / usr/bin/shar/usr/bin/sharroot@localhost:~# echo $? 0
If the end state is 0, the previous command was executed successfully.
Root@localhost:~# ls / usr/bin/sharels: cannot access / usr/bin/share: No such file or directoryroot@localhost:~# echo $? 2
If the end state is not 0, the command execution failed.
How does QRZ 7 compare two numbers in a shell script?
A: use the test command (- gt, etc.) in if-then to compare two numbers, as shown in the following example:
#! / bin/bashx=10y=20if [$x-gt $y] thenecho "x is greater than y" elseecho "y is greater than x" fi
What is the role of the break command in the QRV 8 shell script?
A: a simple use of the break command is to exit the loop in execution. We can jump out of the loop using the break command in the while and until loops.
What is the role of the continue command in the QRV 9 shell script?
Answer: unlike the break command, the continue command only jumps out of the iteration of the current loop, not the entire loop. The continue command is useful in many cases, such as when an error occurs, but we still want to continue to execute the big loop.
QR 10 tells me the syntax of the Case statement in the shell script.
A: the basic syntax is as follows:
Case word invalue1) command1command2... .. lastworthy commandments value2) command1command2. Last_command;;esac
While Loop Syntax in QRU 11 shell script?
Answer: like the for loop, the while loop repeats its command block as long as the condition holds. Unlike the for loop, the while loop iterates until its condition is not true. Basic grammar:
While [test_condition] docommands... Done
How do I make the script executable?
Answer: use the chmod command to make the script executable. Examples are as follows:
What is the role of # chmod axix myscript.shQ:13 "#! / bin/bash"?
Answer: #! / bin/bash is the first line of the shell script, called the shebang line. The # symbol here is called hash, and! It's called bang. It means that commands are executed through / bin/bash.
For Loop Syntax in QRV 14 shell script?
Answer: the basic syntax of the for loop:
For variables in list_of_itemsdocommand1command2... .last _ commanddone
How does QRV 15 debug shell scripts?
Answer: use the'- x 'parameter (sh-x myscript.sh) to debug shell scripts. Another way is to use the'- nv' parameter (sh-nv myscript.sh).
How does the QRV 16 shell script compare strings?
Answer: the test command can be used to compare strings. The test command compares each character in the string.
What are the special variables in QRV 17 Bourne shell (bash)?
Answer: the following table lists the special variables set by Bourne shell for the command line.
Built-in variable
explain
, 0
Script name on the command line
, 1
The first command line argument
$2
Second command line argument
... ..
…… .
9
Ninth command line argument
$#
Number of command line arguments
$*
All command line arguments, separated by spaces
QRV 18 How to test files in a shell script? QRV 18 in the shell script, how do I test the file?
A: the test command can be used to test files. The basic usage is as follows:
Test
Usage
-d file name
If the file exists and is a directory, return true
-e file name
Return true if the file exists
-f file name
If the file exists and is a normal file, return true
-r file name
Returns true if the file exists and is readable
-s file name
Returns true if the file exists and is not empty
-w file name
Returns true if the file exists and is writable
-x file name
Returns true if the file exists and is executable
QRV 19 how do I write comments in shell scripts?
A: comments can be used to describe what a script can do and how it works. Each line comment begins with #. Examples are as follows:
#! / bin/bash# This is a commandecho "I am logged in as $USER" QRV 20 how does shell get input from the terminal on the script?
Answer: the read command reads data from the terminal (using the keyboard). The read command takes the user's input and places it in the variable you give. Examples are as follows:
# vi / test.shPlease enter your nameLinuxTechiMy Name is LinuxTechiQ:21 test.shPlease enter your nameLinuxTechiMy Name is LinuxTechiQ:21 how to cancel a variable or a variable assignment?
Answer: the "unset" command is used to cancel variables or unassign variables. The syntax is as follows:
How does # unset QRV 22 perform arithmetic operations?
A: there are two ways to perform arithmetic operations:
Use the expr command (# expr 5 + 2) 2. Use a dollar sign and square brackets ($[expression]) for example: test=$ [16 + 4]; test=$ [16 + 4]
What is the basic format of QRV 23 do-while statements?
A: the do-while statement is similar to the while statement, but executes the command before checking the conditional statement (LCTT translation: meaning at least once. ). Here is the syntax for using the do-while statement
How does do {statements} while (condition) QRV 24 define functions in shell scripts?
A: a function is a block of code with a name. When we define a code block, we can call the function name in our script, and the block will be executed. The example is as follows:
$diskusage () {df-h;}
How do I use BC (bash Calculator) in shell scripts?
Answer: use bc in shell scripts using the following format:
Variable= `echo "options; expression" | bc` "what are the questions for the Linux Shell script interview"? thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.