How to use PHP as a Shell scripting language. We all know that PHP is a very good dynamic web page development language (fast speed, short development cycle ......). However, only a few people realize that PHP can also be well written as S.
We all know that PHP is a very good dynamic web page development language (fast speed, short development cycle ......). However, only a few people realize that PHP can a
curly braces to tell the shell that we're printing num variables:
num=2
echo "This is the ${num}nd"
This will print: This is the 2nd
There are many variables that are automatically set by the system, which are discussed later when these variables are used.
If you need to work with mathematical expressions, you need to use programs such as expr (see below).
In addition to the usual shell variables that are
: This article describes how to use PHP as a Shell script language. For more information about PHP tutorials, see. We all know that PHP is a very good dynamic web page development language (fast speed, short development cycle ......). However, only a few people realize that PHP can also be a good language for writing Shell scripts. When PHP is used as a language for writing
@ artemis dbrogdon] $ scriptname. ph Darrell BrogdonThe Shell script will output on the display:Hello, Darrell Brogdon! How are you today?[Dbrogdon @ artemis dbrogdon] $When PHP is used as a dynamic web page programming language, it also contains the array "$ argv", but there are some differences with this: when PHP is used as the Shell scripting language, "$ ar
Script This article originates from: http://phpuser.com Author: y10k translation (2002-10-15-06:02:00)
--English Original: Darrell Brogdon, published in Http://www.phpbuilder.com/columns/darrell20000319.php3)
Many people may have wanted to use PHP to write some of the regular mail, such as the program, but there is no way to execute PHP on a regular basis; when I went to Phpbuilder, I found this article, so I want to give you a translation (at the same time make some changes), I hope to be usef
output on the monitor: Hello, Darrell brogdon! How are are you today?[Dbrogdon@artemis dbrogdon]$ PHP also contains an array of "$ARGV" when writing language as a Dynamic Web page, however, there are some differences: when PHP as a shell scripting language, "$argv [0]" corresponds to the script file name, and when used for dynamic Web page writing, "$argv [1]" Corresponds to the first parameter of the Que
1. Linux Scripting Basics1.1 Basic Introduction to grammar1.1.1 StartThe program must start with the following line (must be placed on the first line of the file):#!/bin/shThe symbolic #! is used to tell the system that the parameters behind it are the programs used to execute the file. In this example we use/BIN/SH to execute the program.When you edit a good script, you must also make it executable if you want to execute the script.To make the script
Tags: exit USB machine $ Example des user created Linu specifiedChapter 23rd using other shellsThe bash shell is the most widely used shell in the Linux distribution. But it's not the only option, and there are other shells you can choose from.23.1 What is dash shellBaidu Encyclopedia said: Dash Shell is a Unix
Shell Scripting Learning The shell is the command parser that converts the user-entered instruction into a program that the appropriate machine can run.The shell is a program that acts as an interface between a user and a Linux system, allowing the user to enter commands to be executed to the operating system, which c
shell is different from the normal program return value that we understand, and the Shell function return value can only be a numeric value, usually to indicate success or failure of the function, 0 for success, and other values to fail. Therefore, it is inappropriate to return the function execution result with the return value of the function. If you return a string, you get an error message: "Numeric ar
use it as the first command option. The FS parameter immediately following the-F option is a regular expression or is provided as the next argument. The field separator character can also be set to be specified using the built-in variable FS. Such as:Awk-f ' \ t ' {...} ' files fs= ' [\f\v] ' filesAbove example the value set by the-F option is applied to the first filegroup, and the value specified by FS is applied to the second group. The-v option initialized must be placed before any programs
the default format for shell scripts written in Windows systems is DOS instead of UNIX, resulting in incorrect output results.Look at the format of the shell script and edit the shell script with VI. Then enter ": Set FF?" If the output end is "Fileformat=dos", you need to modify the format of the file// modify file f
)Redirect in-depth explanationIn general, each Unix/linux command will open three files when it is run:
Standard input file (stdin): stdin file descriptor for 0,unix program reads data from stdin by default.
Standard output file (stdout): StdOut file descriptor for 1,unix program defaults to stdout output data
Standard error file (stderr): The st
What is a shell script sampleLet's look at an example:#!/bin/shcd ~mkdir Shell_tutcd shell_tutfor (i=0; iExample explanation
Line 1th: Specify the script interpreter, here is the interpreter with/bin/sh
Line 2nd: Switch to the current user's home directory
Line 3rd: Create a directory Shell_tut
Line 4th: Switch to the Shell_tut directory
Line 5th: Cycle conditions, 10 cycles
Line 6th: Create a test_1 ... 10.txt file
Li
=/var/Log4Root_uid=0# When $uid is 0, the user has the root user's permission5 #要使用root用户来运行6 if["$UID"-ne"$ROOT _uid"]7 Then8Echo"must is root to run this script."9Exit1Ten fi OneCD $LOG _dir | |{#如果cd没有执行成功就执行大括号中的内容 AEcho"cannot change to Nessarg directory">2 -Exit1 - } thecat/dev/NULL>Messages -Echo"Logs cleaned up" -Exit0 -#退出之前0表示成功, returning 1 means failureThree ways to empty a log1 echo >test.log #输入空的内容 2 >test.log3 cat/dev/null > test.log #查看黑洞, redirect black hole to file 4 app: Kee
Http://www.runoob.com/linux/linux-shell.htmlShell Pass ParametersIn addition, there are several special characters for handling parameters:
parameter Handling
Description
$#
The number of arguments passed to the script
$*
Displays all parameters passed to the script in a single string
$$
The current process ID number for the script to run
$!
ID number of the last process running in the background
, convert uppercase characters to lowercase. option allows you to specify the characters you want to delete, and to condense the inherited characters into one.Common options:-C take Source-char-list's inverse meaning. TR the character to be converted into a character that is not listed in the source-char-list. This option is typically used in conjunction with-D or-S.-C is similar to-C, but handles characters rather than binary byte values.-D self-standard input removes the characters listed in S
file from line 22nd to line 33rd to the end of line 44th.
Sed ' 1,21h;22h;23,33h;44g ' pass
18, move the file from line 22nd to line 33rd to the end of line 44th.
Sed ' 22{h;d};23,33{h;d};44g ' pass
19, only the first word of each line is displayed.
Sed-nr ' s/([^a-z]*) ([a-z]+) ([^a-z]+] (. *)/\2/p '/etc/passwd
20, print the first word and the third word of each line.
Sed-nr ' s/([^a-z]*) ([a-z]+] ([^a-z]+) ([a-z]+] ([^a-z]+) ([a-z]+] (. *)/\2
How can shell scripting be used better? Especially in UNIX and Linux operating systems. Next, let's take a look at how to use shell script programming.
Like other UNIX operating systems and Linux systems, IBM? AIX? The operating system provides several powerful tools to help
Unix/linux Shell Programming Combat: Using embedded documents here documents
First, here documents (embedded documents)Here, documents. As a way of redirecting, instructs the shell to start reading the output at the current location of the source file until it encounters a text row that contains only one word. All lines of text that are read in this procedure ar
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.