The tag has no usage guidance.

learn more… | top users | synonyms

3
votes
1answer
68 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
22 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
35 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
45 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 ...
8
votes
4answers
179 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
378 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
34 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
74 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
27 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 ; ...
2
votes
1answer
89 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
42 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
111 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
201 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
47 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
220 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
265 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
200 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
260 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
346 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
348 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
96 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
47 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
258 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
335 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
183 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"
4
votes
1answer
227 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
487 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
496 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
121 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
153 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
120 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
409 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
761 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
890 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
257 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
185 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
85 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
156 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
588 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 ...
21
votes
6answers
20k 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
1k 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
121 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
322 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
855 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 ...
2
votes
1answer
280 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 ...
3
votes
2answers
2k 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
562 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 ...
10
votes
3answers
10k 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 ...