Linux Shell Script Debugging Techniques (PS4 BASH_XTRACEFD)

Linux Shell Script Debugging Techniques (PS4 BASH_XTRACEFD)

This article continues to share some debugging techniques. 1. Use PS4 for Custom Debug Output You can specify the output format of set -x using the PS4 variable: #!/usr/bin/env bash # ps4.sh # Custom debug prompt export PS4='+ ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' set -x # Now the debug output will show the filename and line number … Read more

Powerful Static Analysis Tool for Linux Shell Scripts!

Powerful Static Analysis Tool for Linux Shell Scripts!

Source fromLinux Mainland Introduction to ShellCheck ShellCheck is a widely used open-source tool designed for Shell script developers, aimed at helping to identify and correct errors in scripts. It can statically analyze various Shell scripts such as bash, sh, ksh, and dash, providing detailed warnings and suggestions to help developers improve the reliability and maintainability … Read more

Daily Linux Knowledge: What is a Shell Script

Daily Linux Knowledge: What is a Shell Script

A Shell is a command interpreter responsible for receiving user input commands and passing them to the operating system kernel for execution. Common shells include Bash (Bourne Again Shell), Zsh, and Ksh, with Bash being the default shell for most Linux distributions. A Shell script is a series of shell commands written in text form, … Read more

Kirin Linux | The Ultimate Showdown: find -exec vs xargs for Efficient Shell Batch Processing

Kirin Linux | The Ultimate Showdown: find -exec vs xargs for Efficient Shell Batch Processing

Note: This article is an original work by Liu Feng from Anyatech. Please respect intellectual property rights. When sharing, please indicate the source. No unauthorized copying, adaptation, or reproduction is allowed. Introduction In Linux system administration and daily development, we often face a common requirement: to find a batch of files that meet certain criteria … Read more

Commonly Used grep Commands in Linux/Shell Scripts

1. Introduction to the grep Command grep is a powerful command used for text searching in Linux/Unix systems. It searches for matching content in files or input streams based on specified patterns (regular expressions or strings) and outputs the lines containing the matches. 2. Basic Syntax of the grep Command grep [options] pattern [file..] pattern: … Read more

Understanding the Execution Mechanism of find . -exec … {} \; in Linux

When we use the -exec option, according to the man[1] manual, there are two ways to end the command: # Ends with \\; find . -name "*.txt" -exec ls -l {} \; # Or ends with + find . -name "*.txt" -exec ls -l {} + The manual mentions that the command must end with … Read more

Commonly Used find Command in Linux/Shell Scripts

1. Introduction to the find Command The find command is a powerful file search tool in Linux/Unix systems that can recursively traverse specified directories, search for files based on various conditions, and perform operations on them. 2. Format of the find Command find [path] [options] [action] 3. Common Options and Examples of the find Command … Read more

Running Shell Scripts in Linux C Code to Retrieve Return Values

When programming in C under Linux to execute Shell commands or scripts, the system function is generally used. However, it only returns whether the execution was successful or failed, without returning the corresponding return value of the executed Shell command or script. The following method can be used to achieve this requirement:Temporary FileSince the return … Read more

Common Command Snippets in Linux

systemd systemctl # Start a service immediately systemctl start nginx.service # Stop a service immediately systemctl stop nginx.service # Restart a service systemctl restart nginx.service # Kill all child processes of a service systemctl kill nginx.service # Reload a service's configuration file systemctl reload nginx.service # Reload all modified configuration files systemctl daemon-reload # Show … Read more