Questions tagged [brace-expansion]

A shell mechanism which is used to generate arbitrary strings.

Filter by
Sorted by
Tagged with
2
votes
1answer
448 views

How do I tell which commands will use brace expansion and which won't?

For instance, this works: $ curl -s -X GET "http://api-int.abc.com/api/{,,,}ukulele/v1/health" This runs 4 curl commands, which is what I want. Meanwhile ping won't use brace expansion: $ ping ...
10
votes
3answers
2k views

Bash expansion hexadecimal

I would like to know if there is a way of using bash expansion to view all possibilities of combination for a number of digits in hexadecimal. I can expand in binaries In base 2: echo {0..1}{0..1}{0....
3
votes
1answer
258 views

backticks inside brace expansion

I'm trying to list the files of httpd processes, and I tried this: ls -l /proc/{`pidof httpd | tr ' ' ','`}/ ls: cannot access /proc/{{28493,28492,28491,28490,28489,28488,28487,28486,28483}}/: No ...
1
vote
1answer
76 views

Bash Brace Shell Expansion Fail [duplicate]

I have 5 files called file1, file2, file3, file4, file5, . I am attempting to run the following command echo "contents" >> file{1,2,3,4,5}. I get the following error when I run this command; -...
7
votes
2answers
951 views

Any way to show each step during the command processing?

set -x just show a final result of the command. Any way to view each step more clear, like pics below.
1
vote
1answer
86 views

How to create more than one subdirectory using ZSH? (on a Debian machine)

I am trying to do this in ZSH: mkdir -p static/{css, js, img} but my ZSH is nagging a bit: zsh: parse error near `}' What am I doing wrong here and what would be the proper way to do this type of ...
5
votes
2answers
3k views

matching files using curly brace expansion in zsh

In bash I can use curly braces to pattern match several files, e.g. ls *.{dot,svg,err} If there's no file for a particular extension, I get a warning, but the remaining files will be listed. ls: ...
1
vote
1answer
9k views

copy a file to a destination with different names

I want to copy a text file to a directory with multiple names with curly braces: cp /path/to/file/a.txt /path/to/file/{b,c,d}.txt But it gives me the error: target '/path/to/directory/d.txt' is not ...
13
votes
4answers
1k views

When is {a,b,c} expanded in bash, when is it not?

A bash script that contains for i in {a,b}-{1,2}; do echo $i; done prints a-1 a-2 b-1 b-2 when executed. This is what I expected - as the {a,b} construct is expanded. However, when (another) ...
8
votes
2answers
10k views

bash combining wildcard expansion with brace expansion

I'm trying to expand a string involving a wildcard and a collection of extensions specified within braces. Nothing seems to work as the example below illustrates. the variable firstList expands ...
0
votes
1answer
111 views

Why does parameter expansion happen before brace expansion in this example?

From https://unix.stackexchange.com/a/7739/674, why does parameter expansion happen before brace expansion in the following example? eval rm foo.{$ext0..$extN}
0
votes
3answers
145 views

Perform parameter expansion before brace expansion? [duplicate]

Bash manual says that brace expansion is performed before any other expansions. I am writing a script which accepts two arguments: #! /bin/bash for b in {$1..$2}; do echo $b; done I run it like: $...
1
vote
1answer
474 views

Bash brace expansion of {a..Z} [duplicate]

In bash, you can do cool brace expansions like this: $ echo {a..z} a b c d e f g h i j k l m n o p q r s t u v w x y z Experimenting around with this, I decided to try some weird things: $ echo {a.....
4
votes
1answer
78 views

Deduplicating Bash Brace Expansions

Brace expansions can produce multiple instances of file names if there is an overlap in the matches. A simple example: mkdir testdir; cd testdir touch abcd for f in *{b,c}*; do something_to "$f"; ...
0
votes
1answer
260 views

echo {Z..A}; out {Z..A};Why? [duplicate]

I'm a new Ubuntu user. I am reading this book "The Linux Command Line: A Complete Introduction" and practicing the code. That's fun, but I have trouble in Chapter 8: ➜ ~ echo {1..10} 1 2 3 4 5 6 7 8 ...
8
votes
1answer
1k views

Append (alter) each array element via parameter expansion (i.e. without printf)?

Let the script below exemplify my quandary.. #!/bin/zsh STUFF=( moose-hoof ovary clydsedale ) echo ${MINE=$(printf "MY-%s " $STUFF)} echo ${MINE_EXP=${STUFF/^/MY-}} MY-moose-hoof MY-ovary MY-...
2
votes
1answer
266 views

Repeat based off user input OS X

I am creating a script which asks a user to enter a message then how many times they would like to display that message. This is what I have so far. message.sh #!/bin/bash echo -en "Enter a ...
5
votes
2answers
527 views

Scrabble helper in bash

I'm trying to make a scrabble helper in bash, which when given a list of characters, finds all the words in the /usr/share/dict/words file. For example, when given the letters a,c,r,t The word cart ...
0
votes
1answer
271 views

How to create multiple dot files using brace expansion?

I want to create a bunch of dot files using brace expansion, but it doesn't work: touch .{a..h} the result is a file .{a..h} is created instead of .a .b .c ...
9
votes
4answers
258 views

Right-to-left shell brace expansion

In zsh (and other shells), if I include an argument like (for example): {a,b,c}{d,e,f} brace expansion turns it into: ad ae af bd be bf cd ce cf For my purposes, the argument order is important, ...
11
votes
1answer
458 views

Why is echo matching some files twice?

$ touch file{1..12} $ echo *e{1..12} file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12 $ echo *{1..12} file1 file11 file12 file2 file3 file4 file5 file6 file7 file8 file9 ...
3
votes
1answer
1k views

Expanding a brace expansion string held in a variable for use in a for loop?

I've got the following script: FOOS=foo{1..5} for i in `echo $FOOS` do echo bar done Now I (think I) get the idea that the brace expansion only works with literals - hence the echo - but all this ...
7
votes
1answer
635 views

bash shellcheck issue with variables in brace expansion

I'm trying to create an array of file names, based on two variable and using brace expansion, like this: #!/bin/bash altdir=/usr arg=abc tries=({.,$altdir}/{$arg,$arg/main}.{tex,ltx,drv,dtx}) for i ...
3
votes
1answer
66 views

Brace expansion and compound command

I do not understand why these two loops are different. It must have something to do with when the brace expansion is performed and how white space is interpreted for i in b{e,\ }s ; do echo $i ; ...
3
votes
1answer
302 views

Expanding {a..d} to a b c d in zsh

In bash, {a..d} expands to a b c d. Currently this is not happening for me in zsh, and my googling has returned conflicting results. Some results suggest that {a..d} should work -http://zsh....
2
votes
2answers
322 views

Braces don't work when there is a single element

I am able to scp files based on their extensions as, scp sk@localhost:/home/sk/*.{txt,text} . But when I try to scp a single extension type, it fails, scp sk@localhost:/home/sk/*.{txt} . I was ...
3
votes
1answer
940 views

Can bash brace expansion be performed within quotes

In an attempt to dry up my bashrc, I tried changing this, CDPATH=".:~/Development:~/Development/resources:~" to this, CDPATH=".:~/Development{,/resources}:~" But I found the brace expansion wasn't ...
2
votes
2answers
2k views

Bash decimal to binary conversion explanation

When converting decimal values to their binary representation, it is possible to use the following commands: val=12 D2B=({0..1}{0..1}{0..1}{0..1}{0..1}) echo ${D2B[$val]} While this works, I am ...
2
votes
1answer
439 views

Expand variable in brace expansion [duplicate]

I am trying to enumerate a range of integers using a variable but having some trouble. When I type echo {1..5} I get 1 2 3 4 5 However, when I type a variable, I am unable to get the enumeration. ...
4
votes
2answers
1k views

brace expansion and * expansion

Assume in the working directory, there is only one djvu file. I would like to backup the file into a file with file name having extra .bk at the end. cp *.djvu{,.bk} copies the djvu file into a file ...
3
votes
1answer
2k views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
3
votes
2answers
468 views

How do you stop a bash shell expansion?

I know some methods for stopping process. When I type: echo {1..999999} > filename.txt I can't stop it from running. I can stop other processes with Ctrl+C | Ctrl+D | Ctrl+\ and etc. But none ...
10
votes
1answer
1k views

Why does brace expansion range use two dots instead of three (ellipsis)?

I finally understood/discovered why I never got to using bash's (and also zsh's) brace expansion range properly: the syntax is {1..10} instead of what I assumed to be an ellipsis, i.e. {1...10}. May ...
4
votes
3answers
1k views

Create arrays with brace expansion in loop

I would like to generate a number of arrays that differ only by year. In the loop, I create the arrays with brace expansion and a variable. I tried the following code without success: LIST={JF,JFE,...
2
votes
1answer
2k views

Bash Brace Expansion & Variables [duplicate]

I have a find command: find Directory/{Alpha,Bravo,Charlie} arg1 arg2 I want to replace Alpha,Bravo,Charlie with $find_dir find Directory/{$find_dir} arg1 arg2 however the latter expands to find ...
3
votes
2answers
515 views

How to perform command substitution before brace expansion?

I would like to perform command substitution before brace expansion, but couldn't: $ ls {$(seq -s , 13 20)}.pdf ls: cannot access {13,14,15,16,17,18,19,20}.pdf: No such file or directory How can I ...
2
votes
1answer
74 views

Is there a way to express fixed size loops as loop-less expansion statement in bash?

I was wondering whether expansion of {} in bash shell, e.g. of command /path/to/file{1,2,3} works "horizontally", i.e. command /path/to/file1 /path/to/file2 /path/to/file3 or "vertically", i.e. ...
4
votes
2answers
355 views

Brace expansion does not work for less than 2 arguments

I was expecting brace expansion to work for any number of arguments. However, for n=1 I get the following: $ find models/nsf-projects-{7}* models/nsf-projects-{7}.rdf For n>1 expansion occurs as ...
5
votes
2answers
785 views

How can I force bash to deallocate a brace expanded variable without name?

For benchmarking, I ran the command: for i in {1..100000000}; do echo "$i" line >> file done Bash expanded the braces and stored the list 1 2 3 4 5 6 ... 100000000 in memory. I thought ...
2
votes
2answers
720 views

How to combine arithmetic expansion and brace expansion? [duplicate]

Can peoples combine arithmetic expansion and brace expansion? $ for i in {$((1 + 1))..5}; do echo $i; done; {2..5} $ echo "bash laughs at me"
5
votes
1answer
361 views

`seq` and bash brace expansion failing

IINM my system is failing when bashing for i in {0..10000000}; # Seven zeroes. do false; done # `bash` exited and its `tmux` pane/window was closed. or for i in $(seq 0 10000000); # Seven ...
8
votes
4answers
1k views

How can I suppress the space between generated arguments during brace expansion?

I used the following command to create a list of URLs that I want to test: echo -e localhost:8080/reports/{promos,promo-updates,scandown}/{130,139,142}{,-unburdened,-burdened}{,.pdf,.xls,.xlsx,.csv,....
4
votes
2answers
2k views

How can I list the info for an array of /dev/disks using bash expansion or substitution?

I want the output of: diskutil list; diskutil info [multiple devices] Without having to do: diskutil info disk0; diskutil info disk0s1; diskutil info disk1 ...etc For example, with many builtin ...
5
votes
2answers
192 views

Brace compression

I love brace expansion (e.g. rm file.{0..5}). I find it a lot easier to read than the expanded version. Is there a quick and easy way of doing the opposite? For example given the input www.example....
7
votes
3answers
1k views

Can I use variables inside {} expansion without `eval`?

Can I use variables inside {} expansion without appealing to eval? If so, how? This doesn't work: $ touch 1.foo 1.bar $ ls 1.{foo,bar} 1.bar 1.foo $ extensions=foo,bar $ ls 1.{$extensions} ls: ...
3
votes
3answers
198 views

'Binding' Bash Curly Braces

In Bash, echo a{b,c}d{e,f} prints abde abdf acde acdf The output I'd like to see is abde acdf In other words, given N parameters, I'd like Bash to use the ith parameter within each ...
1
vote
3answers
759 views

Reversing the value key pairs of array using sed or pattern replacement or brace expansion?

#!/bin/bash arr=(a b c d) declare -A brr for i in ${!arr[@]} do brr[${arr[$i]}]=$i done echo ${brr[@]} #0 1 2 3 Is there any way to reverse the values and key pairs ...
9
votes
3answers
4k views

Why is brace expansion not supported?

Do I have to do any configuration to start brace expansion? When I run mkdir {1..10}, it just creates a dir naming {1..10}.
12
votes
3answers
3k views

Possible to use brace (permutation) and array expansion simultaneously?

Bash's {} brace expansion syntax allows for creating easy permutations # echo {b,c,d}{a,e,i,o,u} ba be bi bo bu ca ce ci co cu da de di do du However it's not clear to me if/how it's possible to use ...
5
votes
2answers
2k views

How to do multiple brace expansions without combinatorial explosion?

I often use brace expansion on the command line, because it's handy. Example {foo,bar} expands to: foo bar Multiple brace expansion also expand, e.g.: {foo,bar}Q{foo,bar} would expand to: ...