shell中的set -- "$x"和set -- $x的使用

先看下set --的英文使用说明
set –

Set 1 t o t h e v a l u e o f   x , e v e n i f i t b e g i n s w i t h     o r   +   : s e t " 1 to the value of x, even if it begins with '-' or '+' : set -- " x"

Set the positional parameters to the expansion of x, even if x expands with a leading ‘-’ or ‘+’ :
set – $x

set – "$X"就是把X的值返回给$1, set – $X就是把X作为一个表达式的值一一返回

说明:set --是根据分隔符IFS,把值依次赋给$1,$2,$3,例子2就是展示这个。

例子1:

通过这个例子,就可以清楚的看到他们之间的区别。
例子2:

注意的是:
set --x 使用模板是:

oIFS=$IFS //保存系统默认分隔符

IFS=** //设置分割符以便set – 处理字符串使用

IFS=$oFIS //还原系统默认分隔符

我之前犯了个低级错误:
IFS=oIFS 这样会导致’o’,‘I’,‘F’,'S’都是分隔符


本文来自 fw63602 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/fw63602/article/details/52799073?utm_source=copy

猜你喜欢

转载自blog.csdn.net/u011350541/article/details/82852911