Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [brace-expansion]

A shell mechanism which is used to generate arbitrary strings.

6
votes
2answers
567 views

Loop in macOS not working

I need to execute the following shell script in my macOS terminal. The loop never executes more than its first iteration. function execute_function() { # Launch job number_of_jobs=$1 echo "...
2
votes
1answer
48 views

Combine brace and variable expansion in one line

I would like to have a logging function that takes filenames as arguments and replicate the stdout to all of these files. This is what I have come up so far: function logger() { exec > >(...
6
votes
1answer
297 views

Bash: Why does this Brace Expression work this way?

this is a bash 4 specific question. I am somewhat familiar with the bash Brace Expressions and I have read the manual but I do not understand how it actually works. I guess it has to do with the ...
2
votes
2answers
27 views

How do ranges in dash work?

I'm trying to figure out how to rush the following bash script in dash. for x in {1..5} do for y in {a..c} do echo $HOME$x$y done done Dash does not support brace expansion and I don'...
6
votes
3answers
632 views

Why are bash brace expansions not working for commands?

Why is this working: mkdir /dir/test{1,2,3} and this not? {chown httpd,chmod 700} /dir/test1 -bash: {chown: command not found My Bash Version is: GNU bash, version 4.2.46(2)-release
0
votes
2answers
59 views

Running multiple command against files matching a brace+glob pattern without repeating it

I would like to run a series of commands against a set of files matched by a braces-and-globs pattern, without copy-pasting the pattern all over the place. I've been trying to do this by putting the ...
0
votes
2answers
67 views

Why do tilde prefixes expand prior to assignment, but braces don't

tl;dir In bash, brace expansion occurs before tilde expansion. However, tilde prefixes seem to expand prior to variable assignment and brace expansion doesn't. Why? Details and examples Brace ...
0
votes
1answer
29 views

Can variable-substitution-syntaxes be unified?

Can these two variable-substitution-syntaxes combined into one? rm "$s_a/$domain.conf" 2>/dev/null rm "$s_e/$domain.conf" 2>/dev/null like: rm "$s_{a,e}/$domain.conf" 2>/dev/null
2
votes
3answers
68 views

Create alphabetic index with letters repeating

I am running Debian 9. In Bash I can echo {a..z} for the alphabet, or echo {a..z}{a..z} to print letter combinations. However, I would like to generate an index with: a b c d etc. then aa bb cc dd etc....
2
votes
1answer
38 views

Generate brace expansion from list of files

This brace expression will generate a list of files: $ touch {foo{.t,t.t},other.txt,test{,.{ascii,t{est.qt,x{t,xt}}}}} $ ls foo.t foot.t other.txt test test.ascii test.test.qt test.txt test.txxt ...
2
votes
1answer
76 views

bash in-line brace expansion

Does bash/readline have a binding or a function that a key combination can be binded to in order to expand in-line braces? Similar to the way M-* key combination can be used for in-line globbing ...
2
votes
1answer
225 views

'ambiguous redirect' error from Bash

I have three directories a,b,c and each have a file named old.txt I would like to copy the contents of the file new.txt to each of these files. My approach is $ cat < new.txt > {a,b,c}/old.txt ...
7
votes
1answer
357 views

Why in bash {{a,b}.{c,d}} expands to {a.c} {a.d} {b.c} {b.d}

In bash echo {{a,b}.{c,d}} expands to {a.c} {a.d} {b.c} {b.d} Though nothing is mentioned for brace expansion in bash manual for the type of input I have made My question is why the output is ...
12
votes
3answers
2k views

Why does “cat {foo}” not output foo, but “cat {foo,bar}” does?

I was trying to concatenate text files in sub-folders and tried: cat ./{mainfolder1,mainfolder2,mainfolder3}/{subfolder1}/book.txt > out$var However this did not return anything. So, tried adding ...
0
votes
1answer
105 views

Problems using cp -r command

I have a series of data with format data*.csv where the first data is data658000.csv and last data is data2040000.csv. The data is every 2000 counts. I want to filter the data every 90000 counts so I ...
10
votes
3answers
1k views

Bash brace expansion after a path slash

I'm trying to copy a file to a different name into the same directory using brace expansion. I'm using bash 4.4.18. Here's what I did: cp ~/some/dir/{my-file-to-rename.bin, new-name-of-file.bin} ...
14
votes
3answers
2k views

Why doesn't systemctl\ {restart,status}\ sshd\; work?

The output of the above command when passed through echo is: # echo systemctl\ {restart,status}\ sshd\; systemctl restart sshd; systemctl status sshd; Even if I paste the output to the terminal, the ...
0
votes
2answers
56 views

Bash script loop with zero paddings for the numbers

So I need to repeatedly try submitting a 4 digit number to a port on the local host, and then evaluate the response I get from the port if it contains a specific string, which I do with grep. I used ...
0
votes
1answer
143 views

How can I expand a list of letters/numbers in ash?

In busybox, the default shell is ash, so some familiar tricks in bash are not available. One thing I would like to do is expand a list of letters, like {a..z}, which would expand to a b c d e f g h i ...
19
votes
6answers
5k views

cat a very large number of files together in correct order

I have about 15,000 files that are named file_1.pdb, file_2.pdb, etc. I can cat about a few thousand of these in order by doing: cat file_{1..2000}.pdb >> file_all.pdb However, if I do this ...
0
votes
2answers
62 views

Possible logic or semantic error in CentOS7 vs RHEL7

I came across this problem a few weeks ago but I thought it was my system acting up. But after a couple of investigations, I believe this could be a bug. Or maybe I am wrong. When attempting to echo ...
0
votes
1answer
50 views

mkdir -p dir with braces created wrongly

I executed the following code in Ubuntu server 16.04 xenial: mkdir -p /root/backups/{db, dirs} I recall that in another system, it worked like charm creating all 3 dirs: /root/backups/ /root/...
3
votes
4answers
546 views

How to use bash tricks to type out list of redundant strings which vary only in a couple characters?

This has probably been asked before, but I'm unsure how to word it. I want to type out a series of strings, which are basically string1, string2, string3; but without the redundant typing. So is there ...
1
vote
3answers
432 views

Use variable inside bash brace expansion [duplicate]

I have a program that generates a variable number of pictures, ordered like that: 1.jpg, 2.jpg [...] 10.jpg..etc I can't use *.jpg as input because the 10 will be processed before 2, 3, etc. so I ...
0
votes
2answers
3k views

How does curly brace expansion work in the shell?

The command echo {1..3}-{1,2} prints 1-1 1-2 2-1 2-2 3-1 3-2. I understand the way those curly braces can be used. But what actually are they? Is it the job of sh / bash to parse/expand them and ...
0
votes
1answer
672 views

GNU find: get absolute and relative path in -exec

I have a command (not echo!) that I want to run which takes an absolute path and a relative path. How do I get these two arguments? Attempt: d=/tmp/foo; find "$d" -type f -exec bash -c 'echo d=${1:$...
19
votes
3answers
2k views

Nested brace expansion mystery in Bash

This: $ echo {{a..c},{1..3}} produces this: a b c 1 2 3 Which is nice, but hard to explain given that $ echo {a..c},{1..3} gives a,1 a,2 a,3 b,1 b,2 b,3 c,1 c,2 c,3 Is this documented ...
6
votes
3answers
479 views

Why is there a number in the zsh parameter expansion ${1-$PWD}

I have this script I'm basing my current script off of. I just don't understand why he has typeset result part dir=${1-$PWD} in there. I get the same result if I just write dir=$PWD. With typeset is $...
-4
votes
2answers
807 views

Using touch command and wildcard how to solve?

In order to demonstrate the use of 'wildcard' characters, issue a command to create the following empty files in your current directory: a1 a11 a123 a1234 a23 a22 a3 1 11 123 someone told me ...
0
votes
4answers
105 views

How do you cycle through sequentially numbered aliases?

I have 3 aliases. They are named echo1, echo2, echo3 How do i execute all 3 of them as part of a larger command? $ alias echo1='echo 1' $ alias echo2='echo 2' $ alias echo3='echo 3' $ echo1 1 $ ...
6
votes
2answers
649 views

Bash brace expansion to remove part of filename

Is it possible to remove rather than adding substring to a filename using bash brace expansion? Considering the following scenario, one can add a suffix to a filename by using the below technique: ...
1
vote
1answer
380 views

Is that possible to rename the file with sequence number using {1..10}

I have doubt. I have to rename the file with sequence number 1 to 10. i am able to create a file with following parameter. touch file.$(date +%Y).$$.{1..10} But i can't rename the file using the ...
0
votes
1answer
103 views

Bash 3.2.57 brace expansion {01..09} [duplicate]

I'm having a little issue, I can't go for bash v.4 I'm stick to use bash 3.2.57. I'm inputting my script in this form logs_logs_2017-04-{02..06}.tar.bz2 but since bash 3.2.57 doesn't support brace ...
0
votes
3answers
134 views

Creating a range of numbers from 08 to 10 in bash doesn't include 0 in front of one digit numbers

On my local machine, where I run CentOS 7.2, when I do this: for i in {8..12}; do echo ${i}; done I got: 8 9 10 But when I do this: for i in {08..10}; do echo ${i}; done I got: 08 09 10 But on ...
3
votes
1answer
332 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 ...
8
votes
3answers
1k 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
203 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
67 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
420 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
62 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 ...
5
votes
2answers
2k 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
8k 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 ...
12
votes
4answers
831 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) ...
9
votes
2answers
7k 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
98 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
98 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
315 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
72 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
182 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 ...
7
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-...