A shell mechanism which is used to generate arbitrary strings.

learn more… | top users | synonyms

0
votes
1answer
38 views

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

From http://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
52 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
30 views

Bash brace expansion of {a..Z}

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 ...
4
votes
1answer
42 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
34 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 ...
3
votes
1answer
102 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 ...
2
votes
1answer
26 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
61 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
47 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
184 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
386 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 ...
0
votes
1answer
43 views

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

As a complete newbie to bash, 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 - ...
0
votes
0answers
24 views

How to reference a variable by its string “name”? [duplicate]

Say for example... #!/bin/bash a1=one a2=two a3=three for x in {1..3}; { echo -n "\$a$x "; } Actual.. $a1 $a2 $a3 Expected.. one two three How can one echo, reference, call, or what ...
5
votes
1answer
90 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 ...
2
votes
1answer
29 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
112 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 ...
0
votes
2answers
53 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 ...
2
votes
1answer
139 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 ...
2
votes
2answers
319 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
48 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 ...
4
votes
2answers
260 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 ...
1
vote
1answer
338 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
208 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 ...
8
votes
1answer
312 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 ...
2
votes
2answers
388 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: ...
1
vote
1answer
422 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 ...
1
vote
2answers
101 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
49 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. ...
3
votes
2answers
260 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
363 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
196 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
232 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); # ...
7
votes
4answers
543 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 ...
3
votes
2answers
547 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
136 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 ...
4
votes
2answers
163 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
125 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 ...
1
vote
3answers
432 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 ...
3
votes
3answers
924 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}.
7
votes
2answers
1k 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 ...
1
vote
2answers
284 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: ...
2
votes
1answer
213 views

cp : short way of copying [closed]

I don't remember exactly but there was either cp or mv command which I was able to do something like this with: cp file{.cpp, .cpp.org} Which would copy file.cpp and make a copy named file.cpp.org. ...
1
vote
2answers
89 views

Renaming a file to a shorter name easily using something like brace expansion

So I know about using braces when backing up a file to making this sweet and easy like so: cp -v original.xml{,.backup} But if I wanted to restore the original I would have to do this cp -v ...
3
votes
2answers
158 views

Bash expansion of ${@} as command

I have a parent script while read cmd do nohup ./script ${cmd[@]} &>> log & done < ~/list that executes this child script while true do eval "${CMD[@]}" #${CMD[@]} ...
1
vote
1answer
633 views

Quoting curly braces in the shell [duplicate]

I found examples of different quoting for curly braces for find, but I could not find an explanation. The possible choices are: 1. {} 2. '{}' 3. "{}" And they all seem to work fine. Is ...
4
votes
2answers
2k views

How could I make multiple symbolic links for multiple directories, conveniently

lrwxrwxrwx 1 deploy users 20 1월 23 18:15 v122 -> /home/files/video122 lrwxrwxrwx 1 deploy users 20 1월 23 18:15 v123 -> /home/files/video123 lrwxrwxrwx 1 deploy users 20 1월 23 ...
24
votes
6answers
23k views

How to create a sequence with leading zeroes using brace expansion

When I use the following, I get a result as expected: $ echo {8..10} 8 9 10 How can I use this brace expansion in an easy way, to get the following output? $ echo {8..10} 08 09 10 I now that ...
3
votes
1answer
2k views

mkdir multiple directories with a subdirectory name having space in it

I want to make multiple directories in one go. The problem is that one of the sub directories have a name with a space in it. The directory structure i want to make is as follows. project /level ...
2
votes
2answers
125 views

Expand less-than sign when using multios and brace expand

With zsh multios set (setopt multios) it's possible to do things like: < in1 < in2 > out and: < in > out1 > out2 which is very convenient. I want to combine this feature with ...
5
votes
2answers
328 views

Why arguments in braces do not expand in this case?

For example, I want to put some file names inside braces for expansion like this: $ ls blue_texture blue_waves green_light $ ls -m | tr -d ' \n' blue_texture,blue_waves,green_light $ echo ...