Under linux shell file under windows bat file conversion with each other

shell (Linux, Solaris) bat ( windows) Meaning
# rem comment line
/【directory】/【directory】/.../【directory】/ [disk]: \ [directory] \ [directory] \ ... \ [ directory] \ path
[variable] = [filename], LBSAM set [variable] = [filename], BSAM the file name assigned to the variable
[variable] = [setpoint]

[Variable] = "[Setting value]"

[Variable] = '[Setting value]'

[Variable]] = [setpoint; export [variable]

[] = [export variable setpoint]

set variable [] = [] variable assignments setting values
unset variable [variable]] = [set initialization of variables
$ {variable}} {

$ [Variable]

% []% Variable
variable references

※ If the variable in an if statement and for loop is assigned the case,

Need to use when referring to the! [Variable]!.

※ If you use the! [Variable]!, You want to add (delayed environment variable)

setlocal enabledelayedexpansion

[Digital] $
$ [Digital]} {

% When [Digital] shell / bat started, passed in the first [Digital] argument
passed when the $ 1 /% 1 → start the first argument

[Variable] = `basename $ 0 .sh` set [variable] =% ~ n0
this shell / bat file name assigned to the variable

variable = test test1.sh/test.bat →

[Variable] = `dirname [file]` for %% i in ( "[file]") do (set [variable] = %% ~ dpi)
get assigned to a variable that contains the file path

Example:

shell:

path1=`dirname /home/dir1/dir2/test.txt`

path1=/home/dir1/dir2

bat  :

for %%i in ("D:\dir1\dir2\test.txt") do (

  set path2=%%~dpi

)

path2 = D: \ dir1 \ dir2

[Variable] [file] = `basename` for %% i in ( "[file]") do (set [variable] = %% ~ nxi) get assigned to a variable that contains the file path
example:

shell:

filename1=`dirname /home/dir1/dir2/test.txt`

filename1=test.txt

bat  :

for %%i in ("D:\dir1\dir2\test.txt") do (

  set filename2=%%~dpi

)

filename2=test.txt

? [Variable] = $ result set [variable] on =% errorlevel% a command is assigned to the variables
if [[Conditions]]; then
    [Process 1]
else
    [process 2]
fi if [Conditions] (
    [Process 1]
) the else (
    [2] processing
)
※ inside the shell if statement (if [Test conditions]) and

Like (IF [condition] []) mean

 IF [$ [variable] [value] -eq]; then if%] [% equ [variable] value (equal to the
 IF [$ [variable] [value] -ne]; then if%] [% neq [variable] NUMERICAL (not equal to the
 IF [$ [variable] [value] -lt]; then if%] [% lss variable [] value (less than
 IF [$ [variable] NUMERICAL -le []]; then if%] [% leq variable [] value (less
 IF [$ [variable] [value] -gt]; then if%] [% gtr variable [] value (greater than
 IF [$ [variable] [value] -ge]; then if% variable [ GEQ] [%] value (greater than or equal
 IF [[variable] $ = "string []"]; then if% variable [%] [text string] == (equal
 IF [[variable] $ = "[characters! string] "]; then if not%] [% variable character string is == [] (not equal
 if [-e] [files or folders]; then if exist [] files or folders (folders or files exist
 if [! -e [file or folder]]; then if not exist] [file or folder (file or folder does not exist
 if [-f [target]]; then for %% A in ( " Object] ") do (set [variable] %% ~ aA =)
 IF"% [variable]: ~ 0,1% "==" - "

If there is ※ shell if [-f [Object]!]; The then time, corresponding to a bat

if  not "%【变量】:~0,1%"=="-" (

It meant to determine whether the object is outside the file

 if [-d] [Object]; then for %% A in ( " Object []") do (set [variable] %% ~ aA =)
 IF "% [variable]: ~ 0,1%" == " d "(the object is a folder
 if [-s] [file]; then for %% A in ( " [] file ") do (set [variable] %% ~ zA =)
 IF variable%] [% gtr 0 ( file size is greater than 0

----------------
Disclaimer: This article is CSDN blogger "lazy little white" in the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_35462323/java/article/details/89335870

Guess you like

Origin www.cnblogs.com/softidea/p/12626026.html