ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Linux下变量的定义及引用

Linux下变量的定义及引用

原创 Linux操作系统 作者:dbasdk 时间:2014-11-12 16:52:57 0 删除 编辑

变量定义方法:(实例)
date=`date -d "last monday" +%Y%m%d`
INdir=/root/shell

典型的变量引用方法:
$date
${date}

系统变量:
$SHELL
${SHELL}

$LANG
$HOME


测试:

[root@CentOS6 shell]# echo $SHELL
/bin/bash
[root@CentOS6 shell]# echo ${SHELL}
/bin/bash
[root@CentOS6 shell]#

[root@CentOS6 ~]# INdir=/root/shell;cd $INdir
[root@CentOS6 shell]#

[root@CentOS6 ~]# INdir=/root/shell;cd ${INdir}
[root@CentOS6 shell]#

[root@CentOS6 ~]# INdir=/root/shell;echo `echo ${INdir}`
/root/shell
[root@CentOS6 ~]# INdir=/root/shell;echo `echo $INdir`
/root/shell
[root@CentOS6 ~]#

[root@CentOS6 shell]# date=`date -d "last monday" +%Y%m%d`;echo $date
20141110
[root@CentOS6 shell]# date=`date -d "last monday" +%Y%m%d`;echo ${date}
20141110
[root@CentOS6 shell]# date=`date -d "last monday" +%Y%m%d`;echo $(date)
2014年 11月 12日 星期三 16:15:42 CST
[root@CentOS6 shell]# date
2014年 11月 12日 星期三 16:15:48 CST
[root@CentOS6 shell]#

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29734436/viewspace-1330021/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-02

  • 博文量
    490
  • 访问量
    1388144