In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use the Bash command in Linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use the Bash command in Linux.
Linux Bash commands for debugging Linux bash programs
Errors are inevitable in the programming process, and sometimes it takes more time to debug programs than to write them, as do shell programs.
The debugging of the shell program mainly uses the Linux Bash command to explain the selection of the program. The form of calling bash is:
Bash-option shell program file name
Several common options are:
-e: exit immediately if a command fails
-n: read commands but do not execute them
-u: treat an unset variable as an error when replacing
-v: display shell input lines when they are read
-x: display commands and their parameters when executing commands
All of the above options can also be referenced within the shell program in the form of "set-option", while "set + option" will prevent that option from working. If you only want to use certain options for a part of the program, you can surround that part with the above two statements.
1. Exit without setting variables and exit immediately
The unset variable exit feature allows the user to check all variables and terminate the execution of the shell program if an unassigned variable is referenced. Shell usually allows the use of unset variables, in which case the value of the variable is empty. If an unset variable is set to exit the selection, an error message is displayed once the unset variable is used, and the program is terminated. The exit option is "- u" without setting a variable.
When shell is running, if it encounters a command that does not exist or cannot be executed, redirect fails or the command ends abnormally, if it is not redirected, the error message will be printed on the terminal screen, and the shell program will continue to execute. To force the shell program to end immediately when an error occurs, you can use the "- e" option to terminate the execution of the shell program immediately.
Tracking of 2.shell programs
The main way to debug a shell program is to track the execution of the program by using the "- v" or "- x" options of the shell command interpreter. The "- v" option causes shell to display every command line it reads during program execution, while the "- x" option allows shell to display each command it executes with a "+" plus a command name at the beginning of the line. And each variable and the value taken by the variable are also displayed, so the main difference between them is that if there is no "- v" before the command line is executed, the original contents of the command line are printed, while the contents of the replaced command line are printed out with "- v".
In addition to using the "- v" and "- x" options of shell, there are some measures that can be taken to assist debugging within the shell program. For example, you can use the echo command in some key parts of the shell program to display the necessary information, which is equivalent to the printf statement in the C language, so that you can know where the program is running and its current state.
Internal Linux Bash commands of the Linux bash program
The Linux bash program interpreter contains some internal commands. Internal commands are not visible in the directory list, and they are provided by shell itself. Common internal commands are: echo, eval, exec, export, readonly, read, shift, wait, and dot (.). The following is a brief description of its command format and function.
1.echo
Command format: echo arg
Function: print out the string specified by arg on the screen.
2.eval
Command format: eval args
Function: when the shell program executes the eval statement, shell reads in the parameter args, combines them into a new command, and then executes.
3.exec
Command format: exec command parameter
Function: when shell executes the exec statement, it does not create a new child process, but instead executes the specified command. When the specified command is executed, the process, that is, the original shell, is terminated, so the following statements of exec in the shell program will no longer be executed.
4.export
Command format: export variable name or: export variable name = variable value
Function: shell can use export to bring its variables down into the child shell so that the child process inherits the environment variables in the parent process. But the child shell cannot use export to bring its variables up into the parent shell.
Note: export statements without any variable names will display all current export variables.
5.readonly
Command format: readonly variable name
Function: identifies a user-defined shell variable as immutable. The readonly command with no arguments displays all read-only shell variables.
6.read
Command format:
Read variable name table
Function: read a line from a standard input device, decompose it into several words, and assign values to variables defined within the shell program.
7.shift statement
Function: the shift statement renames all positional parameter variables as follows: become, become... Each time the shift statement is used in the program, all the position parameters are moved one position to the left in turn, and the position parameter "$#" is reduced by one until it is reduced to 0.
8.wait
Function: is the end of all child processes that shell waits to start in the background. The return value of Wait is always true.
9.exit
Function: exit the shell program. After exit, you can optionally specify a number as the return status.
10. ". (point)
Command format:. Shell program file name
Function: make shell read into the specified shell program file and execute all the statements in the file in turn.
The above is all the contents of the article "how to use Bash commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.