zoukankan      html  css  js  c++  java
  • awk调用shell

    为什么会有这份记录:在帮同学传文件至服务器时,使用了scp,因此链接属性没有建立好,所以向通过awk完成。(更好的是通过tar传递)

    附:awk中调用shell的方法。

    参考:http://hi.baidu.com/leejun_2005/item/7e75be108091f2fd9d778a51

    一。使用所以system()
    
    awk程序中我们可以使用system() 函数去调用shell命令;如果system()括号里面的参数没有加上双引号的话,awk认为它是一个变量,它会从awk的变量里面把它们先置换为常量,然后再回传给shell;如果system()括号里面的参数有加上双引号的话,那么awk就直接把引号里面的内容回传给shell,作为shell的“命令行”。
    
    ryoma@smartpc:~$ awk 'BEGIN{v1="echo";v2="abc";system(v1" "v2)}'
    abc
    ryoma@smartpc:~$
    
    
    ryoma@smartpc:~$ awk 'BEGIN{v1="echo";v2="abc";system(v1 v2)}'
    /bin/sh: echoabc: command not found
    ryoma@smartpc:~$
    
    
    ryoma@smartpc:~$ awk 'BEGIN{v1=echo;v2=abc;system(v1" "v2)}'
    ryoma@smartpc:~$
    
    二。使用print cmd | “/bin/bash”
    ryoma@smartpc:~$ awk 'BEGIN{print "echo","abc"| "/bin/bash"}'
    abc
    ryoma@smartpc:~$
    
    
    ryoma@smartpc:~$ awk 'BEGIN{print "echo","abc",";","echo","123"| "/bin/bash"}'
    abc
    123
    ryoma@smartpc:~$
    
    注意:无论使用system()还是print cmd | “/bin/bash”, awk都是新开一个shell,在相应的cmdline参数送回给shell,所以要注意当前shell变量与新开shell变量问题
  • 相关阅读:
    CentOS 7 如何设置默认启动方式为命令行模式
    Virtual Box配置CentOS7网络
    序列化后成对象转map,再添加到dataList
    centos7 ping: www.baidu.com: Name or service not known
    协议1
    idea查看接口方法实现
    centos关闭防火墙
    myeclipse配置svn
    eas固定ip避免多次申请许可
    jvm配置
  • 原文地址:https://www.cnblogs.com/openix/p/3519078.html
Copyright © 2011-2022 走看看