zoukankan      html  css  js  c++  java
  • Learning_the_bash_Shell_Third_Edition 8/n

    Command Substitution

    The command inside the parentheses is run, and anything the command writes to standard output is returned as the value of the expression. These constructs can be nested, i.e., the UNIX command can contain command substitutions.

     Here are some simple examples:

    • The value of $(pwd) is the current directory (same as the environment variable $PWD).

    • The value of $(ls $HOME) is the names of all files in your home directory.

    • The value of $(ls $(pwd)) is the names of all files in the current directory.

    • The value of $(< alice) is the contents of the file alice with any trailing newlines removed. 

    • To find out detailed information about a command if you don’t know where its file resides, type ls -l $(type -path -all command-name). The -all option forces type to do a pathname look-up and -path causes it to ignore keywords, built-ins, etc.

    • If you want to edit (with vi) every chapter of your book on bash that has the phrase “command substitution,” assuming that your chapter files all begin with ch, you could type:

    vi $(grep -l 'command substitution' ch*)
    

      The -l option to grep prints only the names of files that contain matches.

    “When in doubt, use single quotes, unless the string contains variables or command substitutions, in which case use double quotes.”

    Task 4-5

    The file used in Task 4-1 is actually a report derived from a bigger table of data about albums. This table consists of several columns, or fields, to which a user refers by names like “artist,” “title,” “year,” etc. The columns are separated by vertical bars (|, the same as the UNIX pipe character). To deal with individual columns in the table, field names need to be converted to field numbers.

     

    Suppose there is a shell function called getfield that takes the field name as argument and writes the corresponding field (or column) number on the standard output. Use this routine to help extract a column from the data table.

     cut -f4 -d| albums
    1981
    1984
    1989
    1990
    1993
    
    (lqdjango0601) cor@debian:~/shell$ cat albums 
    Depeche Mode|Speak and Spell|Mute Records|1981
    Depeche Mode|Some Great Reward|Mute Records|1984
    Depeche Mode|101|Mute Records|1989
    Depeche Mode|Violator|Mute Records|1990
    Depeche Mode|Songs of Faith and Devotion|Mute Records|1993
    

      

  • 相关阅读:
    caffe学习笔记(七)solver优化方法
    caffe学习笔记(六)solver及其配置
    caffe学习笔记(五)Blob,Layer and Net 及其对应配置文件的编写
    caffe学习笔记(四)其他常用层及参数
    caffe学习笔记(三)激活层(Activiation Layers)及参数
    caffe学习笔记(二)视觉层(Vision Layers)及参数
    caffe学习笔记(一)数据层及参数
    外网主机A连接内网主机B
    Neural Network and DeepLearning (6.2)深度学习
    将数据库中的符点数的小数位数改为两位
  • 原文地址:https://www.cnblogs.com/winditsway/p/14475973.html
Copyright © 2011-2022 走看看