This week we are checking out more expansion commands with nesting and parameters.

Download HD Download MP4

Last week we started checking out expansions- what they mean, how they work, and how the shell sees and executes them. This week I wanted to touch on a few extra expansion commands you can use and experiment with. This week we're checking out brace expansion. Bracing can make several text strings out of one pattern, with braces around them.

Try echo Front-{A, B, C}-Back. You can also do examples like: echo Number_{1..5} or echo {Z..A}, and nest expansions by doing something like echo a{A{1,2},B{3,4}}b. This can be useful if you need to make lists of files, say if you had a large collection of photos that you need to list, or if you need a list of Directories: if you had a bunch of photos in directories called 2009-1 through 2011-12, you could list those directories by typing mkdir {2009..2011}-0{1..9} {2009..2011}-{10..12} then type ls.

You can expand parameters, but this is usually more useful with shell scripts. For example, type echo $USER to show your username. Type printenv | less to show a list of available variables. Normally with expansion, if you mistype something while typing a command, you'll notice it echos the mistyped pattern. If you mistype a command while doing parameter expansion, it'll give you a blank string.

The output of a command can also be used as an expansion, like this: echo $(ls). ls -l $(which cp) will show us the results of which cp as an argument to the ls command. This'll let us see the cp program without the pathname being known. Here's an example of using pipelines with expansions: file $(ls /usr/bin/* | grep zip). The pipeline became the argument list of the file command. And if you really feel like showing off you can use the old school technique that looks like: ls -l `which cp`.

Now that you know so much about expansion and how it's used, you can see how this will be very useful once you get more advanced with the terminal. Make sure to email me with your thoughts. And be sure to check out our sister show, Hak5 for more great stuff just like this. I'll be there, reminding you to trust your technolust.

Leave a Reply

Your email address will not be published. Required fields are marked *


1 Comment

  • chrisjohnson 3 years ago

    the symbol that you’re referring to is called a backtick. it’s used a lot in databases to distinguish a table, field, or database from a value or keyword.

  • Thanks again for the article post. Cool.

  • First of all I want to say terrific blog! I had a quick question which I’d like
    to ask if you don’t mind. I was curious to know how you center yourself and clear your thoughts
    before writing. I’ve had a difficult time clearing my
    mind in getting my ideas out there. I do take pleasure in writing but it just seems like the first 10 to 15 minutes are usually
    wasted simply just trying to figure out how to begin. Any ideas or hints?
    Many thanks!

  • wholesale jerseys ?H?v? ? g?od tim? wwith wholesale
    jerseys outlet online, cheap ?rice & fine quality wholrsale jerseys

  • I’m really impressed with your writing skills as well as
    with the layout on your blog. Is this a paid theme or did
    you modify it yourself? Anyway keep up the excellent quality writing, it is rare to see a great
    blog like this one these days.

  • china wholesale jerseys ?ut off cheap nhl jerseys ?ith free shippig &
    to? rate cheap nhl jerseys f?om china