2012年8月27日月曜日

${...}, $(...)

${...}:  String Operator
  • String Substitution
    •  
  • String Pattern Matching
  • String Length
$(...):  Command Substitution
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.[10]
    [10] Not available in versions of bash prior to 2.02.
  • 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.

0 件のコメント:

コメントを投稿