#!/bin/bash while ifs=: Read name1 name2 name3 name4 #IFS是从文件读取内容时指定的分割符号, assign the contents of a to the corresponding variable in separate sections. Do echo $name 1 ' | ' $name 2 ' | ' $name 3 ' | ' $name 4 done <a #反引号与 $ () is a command replacement that executes a string in an anti-quote or $ () as a command, but cannot continue to have anti-quotes in the anti-quotes, and $ ( ) can have. ls= ' ls ' echo $LS #单引号完全不解析命令, ignoring all special strings and outputting them as strings. ls= ' ls ' echo $LS #双引号作用与单引号相似, the difference is that it is not so strict that there are 3 special characters in double quotes that cannot be ignored: $,\, ', that is, single quotes will interpret the special meaning of the string, while single quotes are used directly. The ls= "LS" echo $LS #不过如果使用eval命令, allowing the commands in the double quotation marks to be interpreted. ls= "ls" eval "$LS" set--1 2 3 4 #设置参数, the same as the 2 parameters in main C. While [$#-GT 0] # $ #代表参数总数 do echo $ #输出第一个参数 shift 1 #将参数个数减1, and all move to 1 one bit, you can also set 2, move 2 bits at a time, equivalent to I--, i is the total number of parameters. Done #-gt greater than #-lt less than #-ge equals #-le less than or equal to #-eq equals #-ne is not equal to #在脚本里面可以用 $1,$2 ... to accept parameters, but there is another way to accept parameters, which is getopts. While getopts ABC opt #./main.sh-a-b-c can specify parameters and execute the relevant command do case $opt in a) echo "ABCD" ;; b) echo "1234";; c) echo "ABCD";; *) echo "* * * *"; EsacDone
Linux commands (use of the While,shell parameter)