免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2199 | 回复: 13
打印 上一主题 下一主题

请教:"$-"与"$_"区别 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-10-15 11:06 |只看该作者 |倒序浏览
学习shell13问的9) $@ 與 $* 差在哪?

shell script 的位置参数positional parameter 没有讲全面!
其他书籍看到"$-"与"$_",不大理解!
请求:大虾指导!

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-10-15 13:27 |只看该作者

请教:"$-"与"$_"区别

$-存放的是shell当前的一些设置,$_是perl的一个默认变量吧!

论坛徽章:
0
3 [报告]
发表于 2005-10-15 13:35 |只看该作者

请教:"$-"与"$_"区别

在偶的sco ksh下
$>echo $-
ism
$>echo $_
ism
$>echo $-   $_
ism ps
$>echo $_   $
ism ism



sh下
!$ echo $-
s
!$ echo $_
/bin/sh
!$ echo $_ $-
/bin/sh s
!$ echo $- $_
s /bin/sh


实在是看不出来有什么用

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
4 [报告]
发表于 2005-10-15 15:25 |只看该作者

请教:"$-"与"$_"区别

man bash 看看  Special Parameters 那段:
  1.        -      Expands to the current option flags as  specified  upon  invoca‐
  2.               tion,  by  the  set  builtin  command, or those set by the shell
  3.               itself (such as the -i option).

  4.        _      At  shell startup, set to the absolute file name of the shell or
  5.               shell script being executed as  passed  in  the  argument  list.
  6.               Subsequently,  expands to the last argument to the previous com‐
  7.               mand, after expansion.  Also set to the full file name  of  each
  8.               command  executed and placed in the environment exported to that
  9.               command.  When checking mail, this parameter holds the  name  of
  10.               the mail file currently being checked.

复制代码


我在 13 最後一段如此說:
好了,該是到了結束的時候了。
婆婆媽媽的跟大家囉唆了一堆關於 shell 的基礎概念,
目的不是要告訴大家"答案",而是要帶給大家"啟發"...
在日後關於 shell 的討論中,我或許會經常用"鏈接"方式指引回來十三問中的內容,
以便我們在進行技術探討時彼此能有一些討論基礎,而不至於各說各話、徒費時力。
但,更希望十三問能帶給你更多的思考與樂趣,至為重要的是透過實作來加深理解。

是的,我很重視"實作"與"獨立思考"這兩項學習要素,若你能夠掌握其中真義,那請容我說聲:
--- 恭喜﹗十三問你沒白看了﹗ ^_^

论坛徽章:
0
5 [报告]
发表于 2005-10-15 15:37 |只看该作者

请教:"$-"与"$_"区别

[quote]原帖由 "寂寞烈火"]$-存放的是shell当前的一些设置,$_是perl的一个默认变量吧![/quote 发表:


感谢大家的回帖!



明白了一点!

论坛徽章:
0
6 [报告]
发表于 2005-10-15 19:34 |只看该作者

请教:"$-"与"$_"区别

没看明白网中人说的那段英文,能不能举个例子啊

论坛徽章:
0
7 [报告]
发表于 2005-10-15 21:16 |只看该作者

请教:"$-"与"$_"区别

不懂。
在BSD下:
--------
bash-3.00# echo $-
himBH
bash-3.00# echo $_
himBH
bash-3.00# exit
exit
# /bin/sh
# echo $shell

# echo $_
echo
# echo $-
ims
#
---------------

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
8 [报告]
发表于 2005-10-15 21:52 |只看该作者

请教:"$-"与"$_"区别

只看那兩段, 是沒啥意義的.
若能將整個 man bash 看下來, 才會懂.
不過, 這可不是件簡單的事.

论坛徽章:
0
9 [报告]
发表于 2006-01-25 14:52 |只看该作者
$- : 最近执行的foreground pipeline的选项参数
$_ :显示出最后一个执行的命令

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
10 [报告]
发表于 2006-01-27 13:10 |只看该作者
原帖由 boss_juzi 于 2006-1-25 14:52 发表
$- : 最近执行的foreground pipeline的选项参数
$_ :显示出最后一个执行的命令


$_ 是最最后一个命令行参数.

       _      At  shell startup, set to the absolute file name of the shell or
              shell script being executed as  passed  in  the  argument  list.
              Subsequently,  expands to the last argument to the previous com-
              mand, after expansion.  Also set to the full file name  of  each
              command  executed and placed in the environment exported to that
              command.  When checking mail, this parameter holds the  name  of
              the mail file currently being checked.

[ 本帖最后由 yjh777 于 2006-1-27 13:19 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP