Command Line Expansion Commands and Braced Sets

Commands and Braced Sets

  • Command Expansion: $( ) or ``
    • Prints output of one command as an argument to another

      $ echo “This system’s name is $(hostname)”
      This system’s name is
  • Brace Expansion: { }
    • Shorthand for printing repetitive strings

      $ echo file {1,3,5}
      file1 file3 file5
      $ rm -f file{1,3,5}

The bash shell has some special features relating to expansion which significantly improve the power of working at the command line.

Curly braces are useful for generating patterned strings. For example, without the curly braces, the mkdir
command below would take almost two hundred keystrokes to execute.

[amar@amar-pc ~]$ mkdir -p

Use of the backquotes is called command substitution. In command substitution, the command in backquotes is executed and the output of the command is placed on the command line as if the user had typed it in. An alternative syntax for the backquotes is to place the command in parentheses preceded by a dollar sign $( ).

Leave a Comment

%d bloggers like this: