zoukankan      html  css  js  c++  java
  • shell的环境变量

    1./etc/profile 

    用户登录时,自动读取/ect目录下profile文件,此文件包括

    • 全局或局部环境变量
    • PATH信息
    • 终端设置
    • 安全命令
    • 日期信息或放弃操作信息

    2.stty用法

    stty用于设置终端特性。要查询现在的stty选项,使用stty -a

    $stty -a

    stty的一个选项为-g,此选项允许以只读格式保存stty现有设置,便于以后重置回stty.

    3.显示变量

    使用echo命令可以显示单个变量,并在变量名前加$,例如:

    $ DOLLAR=99

    $ echo ${DOLLAR}

    99

    $ LAST_FILE=s2

    $ echo ${LAST_FILE}

    s2

    $ ERROR="This is user: $LOGNAME"

    $ echo ${ERROR}
    This is user: dongjichao

    4.清除变量

    使用unset命令清除变量

    $ PC=enterprise

    $ echo ${PC}

    enterprise

    $ unset PC

    $ echo ${PC}

    $

    5.显示所有本地shell变量

    $ set | more

    6.测试变量是否已经设置

    $ echo "The file is ${FILES:?}"

    FILES: parameter null or not set

    7.显示环境变量

    $ CONSOLE=tty1;  export CONSOLE

    $ echo $CONSOLE

    tty1

    使用env命令可以查看所有的环境变量

    $ env

    8.使用export导出变量

    有一父进程

    $ cat father.sh
    #!/bin/sh
    echo "this is the father"
    FILM="A Few Good Men"
    echo "I like the file :$FILM"
    #call the child script
    export FILM    #去掉此句,在child.sh中变量$FILM则为空
    child.sh
    echo "back to father"
    echo "and the file is :$FILM"

    子进程为
    $ cat child.sh
    #!/bin/sh
    echo "called from father.. i am the child"
    echo "film name is :$FILM"
    FILM="Die Hard"
    echo "changing file to :$FILM"

    运行father输出:

    $ father.sh
    this is the father
    I like the file :A Few Good Men
    called from father.. i am the child
    film name is :A Few Good Men
    changing file to :Die Hard
    back to father
    and the file is :A Few Good Men

  • 相关阅读:
    String类
    数学类
    同一场景下多个图层之间的调用
    茶壶在触摸机制下旋转的三种方式
    犀牛3D模型下载
    纹理--高清设计素材下载
    cocos2d-x-2.x与3.x帧动画实现方式的改变
    toast提示框的实现
    MenuItem创建注意事项
    Cocos2d-x 面试题解 整理01
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2046107.html
Copyright © 2011-2022 走看看