brace-expansion

(zsh brace expansion | seq) for character lists - how?

倖福魔咒の 提交于 2019-11-28 18:01:30
Bash allows me to write the statement, $ for i in {h..k} ; do echo $i ; done but zsh only allows number list expansion such as {8..13} . What's the best workaround? Something like seq for characters... As this is still a top google result, an updated answer: The current release supports bash style {c1..c2} where c1 and c2 are characters: An expression of the form ‘ {c1..c2} ’, where c1 and c2 are single characters (which may be multibyte characters), is expanded to every character in the range from c1 to c2 in whatever character sequence is used internally. For characters with code points

How can I do brace expansion on variables? [duplicate]

感情迁移 提交于 2019-11-28 12:58:11
This question already has an answer here: Brace expansion with variable? [duplicate] 6 answers Consider the following script: #! /bin/bash -e echo {foo,bar} EX={foo,bar} echo ${EX} The output of this script is: foo bar {foo,bar} I would like the the echo command to perform brace expansion on ${EX} . Thus, I would like to see an output of foo bar foo bar I want to create a script where the user can supply a path with curly brackets where every expanded version of it is copied. Something like this: #! /bin/bash -e $SOURCES=$1 $TARGET=$2 cp -r ${SOURCES} ${TARGET} How can I achieve this? See man

Using a variable in brace expansion range fed to a for loop

好久不见. 提交于 2019-11-27 17:05:03
问题 Here is myscript.sh #!/bin/bash for i in {1..$1}; do echo $1 $i; done If I run myscript.sh 3 the output is 3 {1..3} instead of 3 1 3 2 3 3 Clearly $3 contains the right value, so why doesn't for i in {1..$1} behave the same as if I had written for i in {1..3} directly? 回答1: You should use a C-style for loop to accomplish this: for ((i=1; i<=$1; i++)); do echo $i done This avoids external commands and nasty eval statements. 回答2: Because brace expansion occurs before expansion of variables.

(zsh brace expansion | seq) for character lists - how?

拥有回忆 提交于 2019-11-27 10:58:30
问题 Bash allows me to write the statement, $ for i in {h..k} ; do echo $i ; done but zsh only allows number list expansion such as {8..13} . What's the best workaround? Something like seq for characters... 回答1: As this is still a top google result, an updated answer: The current release supports bash style {c1..c2} where c1 and c2 are characters: An expression of the form ‘ {c1..c2} ’, where c1 and c2 are single characters (which may be multibyte characters), is expanded to every character in the

How can I do brace expansion on variables? [duplicate]

痴心易碎 提交于 2019-11-27 07:17:22
问题 This question already has an answer here: Brace expansion with variable? [duplicate] 6 answers Consider the following script: #! /bin/bash -e echo {foo,bar} EX={foo,bar} echo ${EX} The output of this script is: foo bar {foo,bar} I would like the the echo command to perform brace expansion on ${EX} . Thus, I would like to see an output of foo bar foo bar I want to create a script where the user can supply a path with curly brackets where every expanded version of it is copied. Something like

How to store curly brackets in a Bash variable

痞子三分冷 提交于 2019-11-27 07:15:47
问题 I am trying to write a bash script. I am not sure why in my script: ls {*.xml,*.txt} works okay, but name="{*.xml,*.txt}" ls $name doesn't work. I get ls: cannot access {*.xml,*.txt}: No such file or directory 回答1: The expression ls {*.xml,*.txt} results in Brace expansion and shell passes the expansion (if any) to ls as arguments. Setting shopt -s nullglob makes this expression evaluate to nothing when there are no matching files. Double quoting the string suppresses the expansion and shell

Brace expansion with a Bash variable - {0..$foo}

▼魔方 西西 提交于 2019-11-26 01:40:02
问题 WEEKS_TO_SAVE=4 mkdir -p weekly.{0..$WEEKS_TO_SAVE} gives me a folder called weekly.{0..4} Is there a secret to curly brace expansion while creating folders I\'m missing? 回答1: bash does brace expansion before variable expansion , so you get weekly.{0..4} . Because the result is predictable and safe( Don't trust user input ), you can use eval in your case: $ WEEKS_TO_SAVE=4 $ eval "mkdir -p weekly.{0..$((WEEKS_TO_SAVE))}" note : eval is evil use eval carefully Here, $((..)) is used to force