xargs 用法

xargs 用法

2023年7月10日发(作者:)

xargs用法:

ls | xargs -I mv .bak

e,g

ls | xargs -I {} mv {} {}.bak

ls | xargs -I KKK mv KKK // make sure KKK does not appear in ls

command output

String processing:

掐头去尾:

#x=aabbaarealwwvvww

#echo "${x%w*w}"

aabbaarealwwvv

#echo "${x%%w*w}" << aggressive

aabbaareal

#echo "${x#a*a}"

bbaarealwwvvww << aggressive

#echo "${x##a*a}"

realwwvvww

Get substring

# exprsubstrstartpos length

${x:pos:lenght}

#echo ${x:0:2}

aa

Replacement

echo ${x/a/b} << replacement

echo ${x//a/b} << replacement in aggressive way

Set Default Value:

${shell_var-init_value} :假如 $shell_var沒有设定,则使用init_value作返回值。(空值及非空值时不作处理)

${shell_var:-init_value} :假如 $shell_var沒有设定或为空值,则使用init_value作返回值。

(非空时时不作处理)

${shell_var+init_value} :假如 $shell_var设为空值或非空值,均使用init_value作返回值。(沒设定时不作处理) ${shell_var:+init_value} :若 $shell_var为非空值,则使用init_value作返回值。 (沒设定及空值时不作处理)

${shell_var=init_value} :若 $shell_var沒设定,则使用init_value作返回值,同时將

$shell_var赋值为init_value。 (空值及非空值时不作处理)

${shell_var:=init_value} :若 $shell_var沒设定或为空值,则使用init_value作返回值,同时將 $shell_var赋为init_value。 (非空值时不作处理)

${shell_var?init_value} :若 $shell_var沒设定,则將init_value输出至stderr。 (空值及非空值时不作处理)

${shell_var:?init_value} :若 $shell_var沒设定或为空值,则將init_value输出至stderr。 (非空值时不作处理)。

How "--" is used here:

Default Behavior: When this section is listed as "None.", it means that the

implementation need not support any options. Standard utilities that do not accept

options, but that do accept operands, shall recognize "--" as a first argument to be

discarded.

The requirement for recognizing

"--" is because conforming applications

need a way to shield their operands from any arbitrary options that the

implementation may provide as an extension. For example, if the

standard utility

foo is listed as taking no options, and the application

needed to give it a pathname with a leading hyphen, it could safely do

it as:

foo -- -myfile

Print format(paste)

-bash-4.1$ egrep "^rlink|remote_rlink=|protocol"

| paste - - -

rlink rlk_dato03b2_dato03A_rvg remote_rlink=rlk_dato03b3_dato03A_rvg protocol=TCP

rlink rlk_dato03b2_dato03_rvg remote_rlink=rlk_dato03b3_dato03_rvg protocol=TCP

Here "paste - - -" means to combine several lines of output from grep

output in one line.

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688988377a192101.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信