7
votes
4answers
242 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
29 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 ...
4
votes
2answers
77 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 ...
2
votes
1answer
46 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
86 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
243 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 ...
7
votes
2answers
319 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
162 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
57 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
100 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[@]} ...
3
votes
2answers
970 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 ...
6
votes
5answers
4k 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
720 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 ...
5
votes
2answers
230 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 ...
1
vote
2answers
572 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 ...
3
votes
2answers
857 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 ...
1
vote
3answers
433 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 ...
7
votes
3answers
5k 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 ...
2
votes
1answer
135 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 ...
7
votes
2answers
446 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 ...