Questions tagged [brace-expansion]

A shell mechanism which is used to generate arbitrary strings.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

Can't filter file extensions when the list is in a variable [duplicate]

I guess this is a relative simple question, but I can't find the way to access the variable content when doing a git diff, so it lists all the files with specific extension. // This works fine git ...
5
votes
3answers
365 views

Prepend and append a string to each element of $* in shell

I'm looking for the simplest solution that takes $* as input, and expands to each element prefixed and suffixed with a given string: $*=foo bar baz <solution(x,y)>=xfooy xbary xbazy I can do ...
2
votes
2answers
36 views

Brace expansion with elements of an array

In Bash we can already do this: echo foo.{a,b,c} # == foo.a foo.b foo.c How do we get roughly: arr=(a b c) echo foo.{${arr[@]}} # == foo.a foo.b foo.c
0
votes
0answers
11 views

How can I replace either of the range endpoints with a variable? [duplicate]

for i in {1..10}; do printf '\r%2d' $i sleep 1 done printf '\n' I tryed on follow way: 1st_value=1 2nd_value=10 echo $1st_value # thats works echo $2nd_value # thats works for i in {$...
0
votes
3answers
66 views

bash counting script, counts fine ascending, doing error by counting descending

The follow bash script works fine for for high counting number ranges from 1..1000 By high counting number ranges, bigger than 1..1000000, it needs some time to start. In general, it's working fine. ...
4
votes
3answers
295 views

What is the difference between double-quoting and not double-quoting an array in Bash?

While tracking down an error in my shellscript, I found the following behavior in this code snippet: declare -a filelist readarray filelist < <(ls -A) readonly filelist for file in "${filelist[@...
0
votes
3answers
117 views

Bash brace expansion with variables for pattern matching

I want to loop through all files matching a pattern of the form for file in {prefix1, prefix2, ...}*{postfix1, postfix2, ...}; do How can I programmatically replace {prefix1, prefix2, ...} with a ...
1
vote
1answer
269 views

rsync command doesn't work when run as a systemd service

summary: I am trying to set up a systemd timer to regularly backup a directory using the rsync command. I made an rsync command that works when run manually in a terminal, but it doesn't work ...
0
votes
2answers
62 views

Why is Brace expansion with variables not working as expected? [duplicate]

I would like to set a variable (x=100) in the brackets such as x=100 for i in {0.."$x"..50} ;do echo $i done the desire output for i should be 0 50 100 although I get as an output {0..100.....
0
votes
2answers
58 views

How to create file names containing spaces when using brace expansion?

If this command: touch Test{1..3}.txt Allows me to create: Test1.txt Test2.txt Test3.txt What syntax would I need in order to batch create files containing a space in the file names? For example: ...
0
votes
2answers
38 views

Create multiples files with brace expansion combining letters and numbers

I am trying to create a series of files with brace expansions. I want create the files fileA1 to fileZ100 with all possible combinations (Something like touch file[A..Z][1..100]). If I run the ...
0
votes
1answer
107 views

trying bash brace expansion (discrete numbers) using while read line and echo, doesn't expand

I'm going to give a short version of the kind of issue I'm facing. The real application I'm trying to write has many parts, so I've tried to isolate the part where I'm stuck with a small example. My ...
0
votes
0answers
22 views

Failing to refer to multiple files in a bash script using brace expansion [duplicate]

I'm not experienced with bash scripting at all. Here's my simple script to use on my workplace's server (hence PBS). #PBS -lwalltime=24:00:00 #PBS -lselect=1:ncpus=1:mem=20gb export PATH=$PATH:$HOME/...
1
vote
1answer
144 views

how do I loop through selected file extensions in ZSH?

I am looking for a ZSH equivalent to this BASH construct: for file in *.{abc,def,ghi}; do #loop through all files with the extensions .abc, .def and .ghi I cannot find a similar construct for ZSH. ...
0
votes
3answers
62 views

How do I join the results of a command substitution?

I want to create a list of mp3 files like a 1.mp3|a 2.mp3. I have tried echo ${(j:|:)$(echo *.mp3)} and some variations of it, but they don’t work: # too much splitting 01|The|Magic|Finger|01.mp3|...
1
vote
1answer
100 views

Paste & Brace Expansion vs Wildcard

Why does a brace expansion behave differently than wildcard in combination with paste? Example: Assume we have multiple folders, each containing the same-structured tsv and want to create a 'all.tsv' ...
-1
votes
2answers
31 views

bash: why can't I copy 3 files into 3 directories that share a name with the files?

So if I can do this: $ mkdir ./blah_{007,011,090} And end up with three directories... Why can't I do this... cp ../blah_{007,011,090}.swf ./blah_{007,011,090}_src And copy the files into 3 ...
1
vote
1answer
100 views

Understanding fetching mutiple URLs and documents using curl

It's not clear to me how to fetch multiple documents using curl mainly because I do not fully understand the explanation in the curl documentation The curl documentation says: -o, --output <file&...
22
votes
8answers
1k views

Apply brace expansion in “reverse order”

For example {a..c}{1..3} expands to a1 a2 a3 b1 b2 b3 c1 c2 c3. If I wanted to print a1 b1 c1 a2 b2 c2 a3 b3 c3, is there an analogous way to do that? What's the simplest way?
1
vote
1answer
908 views

bash for loop multiple number ranges

I want to run a bash numeric 'for' loop but I want to skip some numbers in between. Example: for num in {1..4, 7..11, 23..34}; do (echo num $num); done or for num in {17..24, 41..48}; do (echo num ...
1
vote
1answer
687 views

Why does this rsync call not work properly?

I made a simple script to perform backup of my NAS. I do it as follows: date="$(date +%Y-%m-%d)" base="/backup" newest="$(ls -1td "$base"/*-*-*/ | head -n 1)" today="$base/$date" dirs="pub,data,...
1
vote
1answer
481 views

cp runs from command line but file not found from script [duplicate]

I have a script to reorganize my directory structure that contains: files=./*"$pattern"I{"$ifirst".."$ilast"}.ext cp ${files} ../"$pattern"/"$i"/ When I run the script, I get an error: ./*S6I{001.....
28
votes
2answers
2k views

What is the difference between `a[bc]d` (brackets) and `a{b,c}d` (braces)?

What is the difference between a[bc]d and a{b,c}d? Why do people use a{b,c}d when there is already a[bc]d?
6
votes
2answers
2k 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
70 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
348 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
77 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'...
8
votes
3answers
1k 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
161 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
193 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
33 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
232 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
153 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 ...
4
votes
1answer
340 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
432 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
385 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
141 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 ...
12
votes
3answers
2k 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
197 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 ...
1
vote
2answers
458 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 ...
24
votes
6answers
8k 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
67 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
71 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/...
4
votes
4answers
596 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 ...
3
votes
3answers
900 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 ...
4
votes
2answers
6k 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
1k 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
3k 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 ...