shell

讲解一

 

1.概念
   位置参数(position parameter)
     运行脚本前(调用函数前),shell 传递给脚本的参数。
   
   
2. 原理
 bash 脚本的位置参数的传递可以做如下理解:
    1. shell将用户输入的命令行 分别赋值给 1, 2, 3, 4, 5....N
    2. 然后将最后一个参数的名称 N 赋值给 #
    例如: ./script.sh  pa1 pa2 pa3 pa4 pa5
    1="pa1";  2="pa2";  3="pa3" ; 4="pa4"; 5="pa5" && #=5  # 一个间接引用

3. 应用: 
   
   echo "$1"      #  打印 pa1
   echo "$2"      #  打印 pa2    
   echo "$#"      #  打印的是最后一个参数的序号, 即位置参数的个数    5
   echo "$(eval echo "/$$#")" #  打印的是最后一个参数的值
   echo "${!#}"   #  打印的是最后一个参数的值

   echo "$@"      #  打印所有位置参数,IFS为间隔符号
   echo "$*"      #  打印所有位置参数,无间隔符号

函数参数传递:函数的值传递,全部都是 字符串的传递,而且是值传递。
   例如:将一个数组名作为参数传递给一个函数时,函数里面使用该参数时,则认为其只是一个字符串。
   e.g:
   #!/bin/bash
   declare -a arr
   func(){
      #$1[0]="first element of array" # error! command not found
      arr[0]="first element of array" # right 
   }
   func arr

tips:   将一个文本文件的内容赋值给一个变量
  这个比较牛: str=$(<file)    #<file ==  0<file
  我写的:read str < <(echo file| tr "/n" " ")

 

 

讲解二

 

 

linux中shell变量$#,$@,$0,$1,$2的含义解释:
变量说明:
$$
Shell本身的PID(ProcessID)
$!
Shell最后运行的后台Process的PID
$?
最后运行的命令的结束代码(返回值)
$-
使用Set命令设定的Flag一览
$*
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。
$@
所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。
$#
添加到Shell的参数个数
$0
Shell本身的文件名
$1~$n
添加到Shell的各参数值。$1是第1参数、$2是第2参数…。
我们先写一个简单的脚本,执行以后再解释各个变量的意义
# touch variable
# vi variable
脚本内容如下:
#!/bin/sh
echo "number:$#"
echo "scname:$0"
echo "first :$1"
echo "second:$2"
echo "argume:$@"
保存退出
赋予脚本执行权限
# chmod +x variable
执行脚本
# ./variable aa bb
number:2
scname:./variable
first: aa
second:bb
argume:aa bb
通过显示结果可以看到:
$# 是传给脚本的参数个数
$0 是脚本本身的名字
$1是传递给该shell脚本的第一个参数
$2是传递给该shell脚本的第二个参数
$@ 是传给脚本的所有参数的列表

 




魔术数字

编辑 锁定
本词条缺少 名片图,补充相关内容使词条更完整,还能快速升级,赶紧来 编辑吧!
魔术数字(magic number)是程式设计中所谓的直接写在程式码里的具体数值(如“10”“123”等以数字直接写出的值)。虽然程式作者写的时候自己能了解数值的意义,但对其他程式员而言,甚至制作者本人经过一段时间后,会难以了解这个数值的用途,只能苦笑讽刺“这个数值的意义虽然不懂,不过至少程式会动,真是个魔术般的数字”而得名。



理由编辑

因为下述理由,一般认为程式码中不应该含有魔术数字。
一、数值的意义难以了解
二、数值需要变动时,可能要改不只一个地方

例1:price_tax = 1.05 * price
例1是对输入的价格(price)计算含税(price_tax)售价的程式。 但税率并不是万年不变,当政府调整税率时,会有修改程式的必要。 这里“1.05”就是一种魔术数字,“为什么是1.05”会让人无法马上了解。
下面是去掉魔术数字的范例,程式容易了解也容易修正。
例1 (修正):TAX = 0.05 price_tax = (1.0 + TAX) * price
例2:setColor("text", 0xffffff)
例2是设定以白色显示程式码。 然而十六进制的色码0xffffff很难直觉看懂是“白色”,故也算是一种魔术数字。
下面是一种拿掉魔术数字的方式。
例2 (修正):white = 0xffffff setColor("text", white)
像这样,将魔术数字置换成常数或列举型别是经常用来解决魔术数字问题的手段。由于常数可以赋予易懂的名称,可使帮助阅读者了解数值的意义。
当然,在程式初始化部分定义的常数列表不称为魔术数字。



C语言
编辑
在c语言中,把直接使用的常数叫做幻数。在编程时,应尽量避免使用幻数,因为当常数需要改变时,要修改所有使用它的代码,工作量巨大,还可能有遗漏。因此通常把幻数定义为宏或枚举。建议使用枚举,因为它是编译阶段存在的符号,编译器的提示会更清晰、更准确。
#define ARRAY_SIZE 10
enum{ARRY_SIZE = 10}
参考资料

Linux命令替换

Linux命令替换和重定向有些相似,但区别在于命令替换是将一个命令的输出作为另外一个Linux命令的参数。常用命令格式为: command1 `command2` 其中,command2的输出将作为command1的参数。需要注意的是这里的`符号,被它括起来的内容将作为Linux命令执行,执行后的结果作为command1的参数。例如: $ cd `pwd`
该命令将pwd命令列出的目录作为cd命令的参数,结果仍然是停留在当前目录下



登录shell和非登录shell

(2012-09-25 14:00:03)
    什么是登录shell: 登录shell是可以用户登录使用的,比如/bin/bash ,/bin/sh ,/bin/csh......一般 Linux默认的用户shell都是bash,也就是你可以登录进去写命令。
    非登录shell:经典的/bin/nologin就是一个非登录shell,也就是说如果一个用户默认的是它,这个用户即使登录进linux也无法使用linux。
    shell是用户和计算机交流的媒介,登录shell保证用户和计算机交流,非登录shell无法让计算机和用户交流。
    关于用户的默认登录shell是在/etc/passwd文件中记录的。
    非登录shell有他特定的用途,比如一个用linux搭建的ftp服务器,并且创建了多个用户,那么就可以将这些用户默认shell改成nologin,这样一来,这些用户虽然是linux上的用户却无法登录进linux主机,只能进入ftp服务器,这样也保证了安全!





Shell 从标准输入或脚本中读取的每一行称为管道(pipeline);它包含了一个或多个命令(command),这些命令被一个或多个管道字符(|)隔开。

事实上还有很多特殊符号可用来分隔单个的命令:分号(;)、管道(|)、&、逻辑AND (&&),还有逻辑OR (||)。对于每一个读取的管道,Shell都回将命令分割,为管道设置I/O,并且对每一个命令依次执行下面的操作:




整个步骤顺序如上图所示,看起来有些复杂。当命令行被处理时,每一个步骤都是在Shell的内存里发生的;Shell不会真的把每个步骤的发生显示给你看。所以,你可以假想这事我们偷窥Shell内存里的情况,从而知道每个阶段的命令行是如何被转换的。我们从这个例子开始说:
复制代码 代码如下:

$ mkidr /tmp/x 建立临时性目录
$ cd /tmp/x 切换到该目录
$ touch f1 f2 建立文件
$ f=f y="a b" 赋值两个变量
$ echo ~+/${f}[12] $y $(echo cmd subst )$ (( 3 + 2 )) > out 将结果重定向到out


上述的执行步骤概要如下:

1.命令一开始回根据Shell语法而分割为token。最重要的一点是:I/O重定向 >out 在这里是被识别的,并存储供稍后使用。流程继续处理下面这行,其中每个token的范围显示于命令下面的行上:

echo ~+/${f}[12] $y $(echo cmd subst) $((3 + 2))
| 1 | |----- 2 ----| |3 | |-------- 4----------| |----5-----|

2.检查第一个单词(echo)是否为关键字,例如 if 或 for 。这里不是,所以命令行不变继续处理。
3.检查第一个单词(echo)是否为别名。这里不是。所以命令行不变,继续处理。
4.扫描所以单词是否需要波浪号展开。在本例中,~+ 为ksh93 与 bash 的扩展,等同于$PWD,也就是当前的目录。token 2将被修改,处理如下:

echo /tmp/x/${f}[12] $y $(echo cmd subst) $((3 + 2))
| 1 | |------- 2 -------| |3 | |-------- 4----------| |----5-----|

5.下一步是变量展开:token 2 与 3 都被修改。这样会产生:

echo /tmp/x/${f}[12] a b $(echo cmd subst) $((3 + 2))
| 1 | |------- 2 -------| | 3 | |-------- 4----------| |----5-----|

6.再来要处理的是命令替换。注意,这里可用递归应用列表里的所有步骤!在这里,命令替换修改了 token 4:

echo /tmp/x/${f}[12] a b cmd subst $((3 + 2))
| 1 | |------- 2 -------| | 3 | |--- 4 ----| |----5-----|

7.现在执行算数替换。修改的是 token 5,结果:

echo /tmp/x/${f}[12] a b cmd subst 5
| 1 | |------- 2 -------| | 3 | |--- 4 ----| |5|

8.前面所有的展开产生的结果,都将再一次被扫描,看看是否有 $IFS 字符。如果有,则他们是作为分隔符(separator),产生额外的单词,例如,两个字符$y 原来是组成一个单词,单展开式“a- 空格-b”,在此阶段被切分为两个单词:a 与 b。相同方式也应用于命令$(echo cmd subst)的结果上。先前的 token 3 变成了 token 3 与
token 4.先前的 token 4则成了 token 5 与 token 6。结果:

echo /tmp/x/${f}[12] a b cmd subst 5
| 1 | |------- 2 -------| 3 4 |-5-| |- 6 -| 7

9.最后的替换阶段是通配符展开。token 2 变成了 token 2 与 token 3:

echo /tmp/x/$f1 /tmp/x/$f2 a b cmd subst 5
| 1 | |---- 2 ----| |---- 3 ----| 4 5 |-6-| |- 7 -| 8

10.这时,Shell已经准备好了要执行最后的命令了。它会去寻找 echo。正好 ksh93 与 bash 的 echo 都内建到Shell 中了。

11.Shell实际执行命令。首先执行 > out 的 I/O重定向,再调用内部的 echo 版本,显示最后的参数。

最后的结果:
复制代码 代码如下:

$cat out
/tmp/x/f1 /tmp/x/f2 a b cmd subst 5




hell执行顺序 (2011-08-18 17:24:17)
标签:

杂谈

分类: Linux


1       将命令行分割成tokens,依据一些固定的metacharacters字符:SPACE、TAB、NEWLINE、;、(、)、<、>、|、和&。tokens则种类包含words(单词)、keywords(关键字)、I/O redirectors(I/O重定向器)和semicolons(;)

2         检查每一个命令的第一个token,看看他们是否是一些关键字,这些关键字不带引号,耶不带反斜杠。如果他是一个开放的关键字(opening keyword)(if 和其他控制结构的开始符,例如:函数、{,(,((,[[),则这个命令其实十一个符合命令(compound command).Shell为复合命令进行内部设置,读取吓一跳命令,并再一次启动进程。如果关键字不是一个复合命令的开始符号(eg.is a control-structure 'middle' like then,else,or do an 'end' like fi or done,or a logical),则Shell会发出一个语法错误信号。 

3         检查每一个命令的第一个token,将它们和别名表对照。如果找到一个匹配,他便替代别名的定义,并回到步骤1;否则,进行步骤4。允许关键字的别名定义(This scheme allows recursive aliases;It also allows aliases for keywords to be defined)。主语,Shell不会执行递归的别名展开:反而当别名展开为相同的命令时他会知道,并体制潜在的递归操作。可以通过引用要被保护的单词的任何部分而禁止别名展开。

4       如果波浪号(~)出现在单词的开头出,则波浪号~替换用户的根目录($HOME)。替换用户的根目录替换成~user。但是有两个特殊的,~+替换成当前目录$PWD,~-替换成当前目录的上以及别目录$OLDPWD

5       执行参数(变量)替换,对于任意一个以$开头的表达式。

6         将任何形式的$(string),执行命令替换。

7       执行形式$((string))的算术表达式(arithmetic expressions)

8         从参数,命令,或者算术替换中找出一些执行结果的部分,并再一次的将它们分割成为单词,这个时候,他就默认的使用$IFS里面的字符作为定姐夫,而不是使用步骤1的那组meta字符。

9         对于*、?以及成对的[...]的任何出现,都执行文件名生成(finename generation)的操作,也就是通配符号的展开。

10       使用第一个单词作为一个命令,然后依照相依的次序查找,也就是作为一个特殊的内建命令,然后作为一般的内建命令,以及最后作为查找$PATH找到的第一个文件

11       在完成I/O重定向和其他一些事情之后,执行命令。
具体如下图所示:
shell执行顺序


        这是一些简单的主要步骤,但并不是所有步骤。在我们进行下面之前,来看一个例子,应该会使你更清楚的了解这一过程,现在假设下面的命令已经运行:
alias ll="ls -l"
      在进一步假设,在用户的根目录下的fred目录存在一个名为".hist527"的文件。并且还已知一个$$变量,他的值为2537;
现在,我们来看看shell进程是如何执行下面命令的
ll $(whence cc) ~fred/.*$($$00)
1     ll $(whence cc) ~fred/.*$($$00)
  将输入串分割成单词。(splitting the input to words)

2       ll 不是关键字,所以步骤二什么也不做。

3       ls -l $(whence cc) ~fred/.*$($$00)
用ls -l替换ll,shell进程在这个时候会重复步骤1到步骤3,步骤二将ls -l分割成两个单词。

4       ls -l $(whence cc) /home/fred/.*$(($$00))
Expanding ~fred into /home/fred .
将~fred替换成/home/fred .

5       ls -l $(whence cc) /home/fred/.*$((253700))
Substituting 2537 for $$ .
将$$变量替换成2537

6       ls -l /usr/bin/cc /home/fred/.*$((253700))
Doing command substitution on "whence cc".
在“whence cc” 执行命令替换。

7       ls -l /usr/bin/cc /home/fred/.*537
Evaluating the arithmetic expression 253700 .
计算算术表达式253700 

8       ls -l /usr/bin/cc /home/fred/.*537
This step does nothing.
这一步,什么也不做

9       ls -l /usr/bin/cc /home/fred/.hist537
Substituting the filename for the wildcard expression .* 537 .
用文件名替换通配附表达式.*537

10       The command ls is found in /usr/bin .

11         /usr/bin/ls is run with the option -l and the two arguments.

这些也仅仅是一些简单的步骤,并不是所有的步骤。还哟两种方法来实现这个过程,一个是通过引号,一个是通过更加先进的命令eval
以上依据一篇英文,参照翻译而来,如转载,请注明出处。

附上英文原版:

We've seen how the shell uses read to process input lines: it deals with single quotes ( ' ' ), double quotes ( " " ), and backslashes ( \ ); it separates lines into words, according to delimiters in the environment variable IFS ; and it assigns the words to shell variables. We can think of this process as a subset of the things the shell does when processing command lines .

We've touched upon command-line processing (see Figure 7.1 ) throughout this book; now is a good time to make the whole thing explicit. [7] Each line that the shell reads from the standard input or a script is called a pipeline ; it contains one or more commands separated by zero or more pipe characters ( | ). For each pipeline it reads, the shell breaks it up into commands, sets up the I/O for the pipeline, then does the following for each command:

[7] Even this explanation is slightly simplified to elide the most petty details, e.g., "middles" and "ends" of compound commands, special characters within [[ ... ]] and (( ... )) constructs, etc. The last word on this subject is the reference book, The KornShell Command and Programming Language , by Morris Bolsky and David Korn, published by Prentice-Hall.

  1. Splits the command into tokens that are separated by the fixed set of metacharacters : SPACE, TAB , NEWLINE, ; ( ,) < > | , and & . Types of tokens include words keywords , I/O redirectors, and semicolons.

  2. Checks the first token of each command to see if it is a keyword with no quotes or backslashes. If it's an opening keyword ( if and other control-structure openers, function { ( (( , or [[ ), then the command is actually acompound command . The shell sets things up internally for the compound command, reads the next command, and starts the process again. If the keyword isn't a compound command opener (e.g., is a control-structure "middle" like then ,else , or do , an "end" like fi or done , or a logical operator), the shell signals a syntax error.

  3. Checks the first word of each command against the list of aliases . If a match is found, it substitutes the alias' definition and goes back to Step 1 ; otherwise it goes on to Step 4. This scheme allows recursive aliases; seeChapter 3 . It also allows aliases for keywords to be defined, e.g., alias aslongas=while or alias procedure=function .

  4. Substitutes the user's home directory ( $HOME ) for tilde if it is at the beginning of a word. Substitutes user 's home directory for ~ user . [8]

    [8] Two obscure variations on this: the shell substitutes the current directory ( $PWD ) for ~+ and the previous directory ( $OLDPWD ) for ~- .

  5. Performs parameter (variable) substitution for any expression that starts with a dollar sign ( $ ).

  6. Does command substitution for any expression of the form $( string ) .

  7. Evaluates arithmetic expressions of the form $(( string )) .

  8. Takes the parts of the line that resulted from parameter, command, and arithmetic substitution and splits them into words again. This time it uses the characters in $IFS as delimiters instead of the set of metacharacters in Step 1.

  9. Performs filename generation , a.k.a. wildcard expansion , for any occurrences of * ? , and [/] pairs. It also processes the regular expression operators that we saw in Chapter 4 .

    Figure 7.1: Steps in Command-line Processing
    Figure 7.1
  10. Uses the first word as a command by looking up its source according to the rest of the list in Chapter 4 , i.e., as a built-in command, then as a function , then as a file in any of the directories in $PATH .

  11. Runs the command after setting up I/O redirection and other such things.

That's a lot of steps - and it's not even the whole story! But before we go on, an example should make this process clearer. Assume that the following command has been run:

 

alias ll="ls -l"

Further assume that a file exists called .hist537 in user fred 's home directory, which is /home/fred , and that there is a double-dollar-sign variable $$ whose value is 2537 (we'll see what this special variable is in the next chapter).

Now let's see how the shell processes the following command:

 

ll $(whence cc) ~fred/.*$(($$00))

Here is what happens to this line:

  1. ll $(whence cc) ~fred/.*$(($$00))

    Splitting the input into words.

  2. ll is not a keyword, so step 2 does nothing.

  3. ls -l $(whence cc) ~fred/.*$(($$00))

    Substituting ls -l for its alias "ll". The shell then repeats steps 1 through 3; step 2 splits the ls -l into two words. [9]

    [9] Some of the shell's built-in aliases, however, seem to make it through single quotes: true (an alias for : , a "do-nothing" command that always returns exit status 0), false (an alias for let 0 , which always returns exit status 1), and stop (an alias for kill -STOP ).

  4. ls -l $(whence cc) /home/fred/.*$(($$00))

    Expanding ~fred into /home/fred .

  5. ls -l $(whence cc) /home/fred/.*$((253700))

    Substituting 2537 for $$ .

  6. ls -l /usr/bin/cc /home/fred/.*$((253700))

    Doing command substitution on "whence cc".

  7. ls -l /usr/bin/cc /home/fred/.*537

    Evaluating the arithmetic expression 253700 .

  8. ls -l /usr/bin/cc /home/fred/.*537

    This step does nothing.

  9. ls -l /usr/bin/cc /home/fred/.hist537

    Substituting the filename for the wildcard expression .* 537 .

  10. The command ls is found in /usr/bin .

  11. /usr/bin/ls is run with the option -l and the two arguments.

Although this list of steps is fairly straightforward, it is not the whole story. There are still two ways to subvert the process: by quoting and by using the advanced command eval .




source命令用法:
source FileName
作用:在当前bash环境下读取并执行FileName中的命令。
注:该命令通常用命令“.”来替代。
如:source.bash_rc. .bash_rc是等效的。
注意:source命令与shell scripts的区别是,
source在当前bash环境下执行命令,而scripts是启动一个子shell来执行命令。这样如果把设置环境变量(或alias等等)的命令写进scripts中,就只会影响子shell,无法改变当前的BASH,所以通过文件(命令列)设置环境变量时,要用source命令。




管道命令和xargs的区别(经典解释)

  10565人阅读  评论(2)  收藏  举报
  分类:

一直弄不懂,管道不就是把前一个命令的结果作为参数给下一个命令吗,那在 | 后面加不加xargs有什么区别
NewUserFF 写道:
懒蜗牛Gentoo 写道:
管道是实现“将前面的标准输出作为后面的标准输入”
xargs是实现“将标准输入作为命令的参数”

你可以试试运行:

代码:
echo "--help"|cat
echo "--help"|xargs cat

看看结果的不同。


试过了,依然不是很确定的明白到底是什么意思,自己再探索一下看看把

如果你直接在命令行输入cat而不输入其余的任何东西,这时候的cat会等待标准输入,因此你这时候可以

通过键盘输入并按回车来让cat读取输入,cat会原样返回。而如果你输入--help,那么cat程序会在标准输出上

打印自己的帮助文档。也就是说,管道符 | 所传递给程序的不是你简单地在程序名后面输入的参数,它们会被

程序内部的读取功能如scanf和gets等接收,而xargs则是将内容作为普通的参数传递给程序,相当于你手写了

cat --help

来自:http://forum.ubuntu.org.cn/viewtopic.php?t=354669

 

补充解释:

在一个目录中有如下三个文件

a.c        b.c            c.c

find   . /   -print命令会打印出三个文件名

find . /    -print | grep a.c  只会打印出a.c这个文件

如果只输入命令grep a.c

那么你在键盘中只输入a.c字符串时,a.c会被打印两次,否则只打印你输入的字符

如果要找三个文件中,那个文件包括有hello字符

find ./ -print | xargs grep hello

 

总结:管道符后不加xargs相当于先将xargs后面的命令回车执行一下再从键盘里输入

管道符前面命令执行的结果内容

加上xargs 相当于直接从键盘输入管道符前面命令执行的结果内容再回车

再总结一下,就是回车的先后顺序不太一样。

 

echo是一种最常用的与广泛使用的内置于Linux的bash和C shell的命令,通常用在脚本语言和批处理文件中来在标准输出或者文件中显示一行文本或者字符串。

 

echo命令的语法是:

   
   
  1. echo [选项] [字符串]

1. 输入一行文本并显示在标准输出上

   
   
  1. $ echo Tecmint is a community of Linux Nerds

会输出下面的文本:

   
   
  1. Tecmint is a community of Linux Nerds

2. 输出一个声明的变量值

比如,声明变量x并给它赋值为10

   
   
  1. $ x=10

会输出它的值:

   
   
  1. $ echo The value of variable x = $x
  2.  
  3. The value of variable x = 10

3. 使用‘\b‘选项

-e‘后带上'\b'会删除字符间的所有空格。

注意: Linux中的选项‘-e‘扮演了转义字符反斜线的翻译器。

   
   
  1. $ echo -e "Tecmint \bis \ba \bcommunity \bof \bLinux \bNerds"
  2.  
  3. TecmintisacommunityofLinuxNerds

4. 使用‘\n‘选项

-e‘后面的带上‘\n’行会在遇到的地方作为新的一行

   
   
  1. $ echo -e "Tecmint \nis \na \ncommunity \nof \nLinux \nNerds"
  2.  
  3. Tecmint
  4. is
  5. a
  6. community
  7. of
  8. Linux
  9. Nerds

5. 使用‘\t‘选项

-e‘后面跟上‘\t’会在空格间加上水平制表符。

   
   
  1. $ echo -e "Tecmint \tis \ta \tcommunity \tof \tLinux \tNerds"
  2.  
  3. Tecmint is a community of Linux Nerds

6. 也可以同时使用换行‘\n‘与水平制表符‘\t

   
   
  1. $ echo -e "\n\tTecmint \n\tis \n\ta \n\tcommunity \n\tof \n\tLinux \n\tNerds"
  2.  
  3. Tecmint
  4. is
  5. a
  6. community
  7. of
  8. Linux
  9. Nerds

7. 使用‘\v‘选项

-e‘后面跟上‘\v’会加上垂直制表符。

   
   
  1. $ echo -e "\vTecmint \vis \va \vcommunity \vof \vLinux \vNerds"
  2.  
  3. Tecmint
  4. is
  5. a
  6. community
  7. of
  8. Linux
  9. Nerds

8. 也可以同时使用换行‘\n‘与垂直制表符‘\v

   
   
  1. $ echo -e "\n\vTecmint \n\vis \n\va \n\vcommunity \n\vof \n\vLinux \n\vNerds"
  2.  
  3.  
  4. Tecmint
  5.  
  6. is
  7.  
  8. a
  9.  
  10. community
  11.  
  12. of
  13.  
  14. Linux
  15.  
  16. Nerds

注意: 你可以按照你的需求连续使用两个或者多个垂直制表符,水平制表符与换行符。

9. 使用‘\r‘选项

-e‘后面跟上‘\r’来指定输出中的回车符。(LCTT 译注:会覆写行开头的字符)

   
   
  1. $ echo -e "Tecmint \ris a community of Linux Nerds" <li class="L1" style="word-wrap:break-word; margin:0px%
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值