The tag has no wiki summary.

learn more… | top users | synonyms

28
votes
5answers
2k views

When do you use brace expansion?

I understand what brace expansion is, but I don't know how best to use it. When do you use it? Please teach me some convenient and remarkable examples if you have your own tip.
11
votes
5answers
8k 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 ...
8
votes
2answers
2k views

Using curly brackets (braces) to create folder structure with `mkdir -p`

As man mkdir states -p, --parents no error if existing, make parent directories as needed When I ran this command mkdir -p work/{F1,F2,F3}/{temp1,temp2} It creates a folder ...
8
votes
3answers
7k views

bash: Use a variable to store stderr|stdout redirection

Is there any way to redirect stdout and stderr via variable like adding command options in script? For example I have a script: #!/bin/bash -x TEST=">/dev/null 2>&1" OPT='-p -v' mkdir $OPT ...
7
votes
4answers
281 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 ...
7
votes
2answers
655 views

How can I use $var in a shell brace expansion of a sequence?

I want to use $var in a shell brace expansion with a range, in bash. Simply putting {$var1..$var2} doesn't work, so I went "lateral"... The following works, but it's a bit kludgey. # remove the ...
7
votes
2answers
490 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 ...
5
votes
2answers
253 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 ...
5
votes
2answers
164 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 ...
4
votes
1answer
157 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); # ...
4
votes
2answers
89 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 ...
3
votes
2answers
231 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 ...
3
votes
2answers
1k 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 ...
3
votes
2answers
1k views

Short way to scp using the same dir/file in origin and target

I am frequently updating files from a development enviroment to a production one in different servers so the paths are the same in both hosts and it becomes kind of a repetitive procedure to update a ...
3
votes
1answer
975 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 ...
3
votes
2answers
64 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 ...
3
votes
3answers
94 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 ...
3
votes
2answers
107 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[@]} ...
2
votes
1answer
114 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. ...
2
votes
1answer
153 views

How can I control bash's brace expansion to do the right thing (which zsh does automatically)?

In zsh, I get the expected result from both of these brace expansions: $ touch file-{001..100} $ touch file-{1..100} The first one gives me files named file-001, file-002, etc., all the way to ...
2
votes
2answers
97 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 ...
2
votes
1answer
30 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. ...
2
votes
1answer
68 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: ...
2
votes
1answer
181 views

Change completion behaviour with brace expansion in zsh

I have got used to using tab-autocompleting inside braces without expanding in zsh. This was possible, while I used zsh with a basic grml-config. Since I migrated to oh-my-zsh, I can't reproduce this ...
1
vote
2answers
262 views

brace expansion other commands besides mkdir?

Found this nifty lifehacking gem to create multiple directories: http://unix.stackexchange.com/a/640/7768 I was wondering if there are other commands support brace expansion?
1
vote
3answers
214 views

Why 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}.
1
vote
2answers
59 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? ...
1
vote
3answers
476 views

Accessing bash [internal] brace expansion iteration number/variable

Question: Is it possible to access which number of a bash iteration is currently being processed? Psuedo-Command mv {1..5}.something.{1..5} $x1.$x2.something Note: This is a logical ...
1
vote
3answers
278 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 ...
1
vote
2answers
186 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: ...
1
vote
2answers
79 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"
1
vote
2answers
65 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 ...
1
vote
1answer
368 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 ...
1
vote
2answers
663 views

Auto-expansion problem with array elements containing an '*' (asterisk)

I'm trying to write me a find script that should later be able to read a list of directories to be excluded from an external file. Whilst I can accomplish that part myself, it's the annoying array ...
1
vote
0answers
44 views

Why is the order of expansions as it is in bash? [closed]

From Bash Reference Manual: The order of expansions is: brace expansion, tilde expansion, parameter, variable, and arithmetic expansion and command substitution (done in a left-to-right ...
0
votes
1answer
40 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 ...