zoukankan      html  css  js  c++  java
  • Shell 中的set --用法

    Shell 中的set --用法

    set 命令为 shell 设定参数变量。许多命令的输出是以空格分隔的值,如果要使用其中的某个数据域,使用 set 非常有效。

    #!/bin/sh
    echo the date is $(date)
    set $(date)
    echo the month is $2
    输出:
    the date is Wed Apr 23 15:34:16 CST 2014
    the month is Apr

    将 date 命令的输出设置为参数表,再通过位置参数 $2 取得月份。因为 date 命令受语言和地域的影响比较大,所以如果目的是取出月份的名字,则应该用 date +%B。

    还可以利用 set 命令来控制 shell 的执行方式。其中最常用的就是 set +x,使脚本程序跟踪显示当前执行的命令。

    再看如下示例:

    [root@python shell]# ls /opt
    file file3 haha mimei
    [root@python shell]# set -- $(ls /opt)
    [root@python shell]# echo $1
    file
    [root@python shell]# echo $2
    file3
    [root@python shell]# echo $3
    haha
    [root@python shell]# echo $4
    mimei
    [root@python shell]# echo $#
    4
    [root@python shell]# echo $@
    file file3 haha mimei

    所有的悲情叙事,都是因为你的基础体能不够
  • 相关阅读:
    Java面試題(实用性高)
    索引的概述?
    给Eclipse提速的7个技巧
    ETL数据仓库
    实用SQL语句大全
    考证
    PL/SQL 程序
    eclipse
    httpd.conf详解,因为php始终报fileinfo扩展无法加载的错
    dockerfile创建镜像及容器
  • 原文地址:https://www.cnblogs.com/gaoyuechen/p/14336063.html
Copyright © 2011-2022 走看看