brace-expansion

bash brace expansion based on variable content not working

主宰稳场 提交于 2020-12-27 05:39:21
问题 how can i make bash expand whatever it finds in a variable i pass to mkdir? so far i've tried using eval and bash -c , but nothing seems to work LEVEL_1=1,2,3 LEVEL_2=a,b,c DATA_L1="/tmp/{$LEVEL_1}" DATA_L2="$DATA_L1/{$LEVEL_2}" for LINE in $(cat file.txt) ; do #"cat" here returns values like #$DATA_L2/yy/data mkdir -pv $LINE #it actually contains e.g. this $DATA_L2/yy/data done i would expect that this will expand to mkdir -p /tmp/1/a/yy/data mkdir -p /tmp/2/a/yy/data mkdir -p /tmp/3/a/yy

How to generate letter sequence list in fish shell

风流意气都作罢 提交于 2020-01-11 11:09:33
问题 In bash you can generate letter sequence easily as "{a..z}", for example $ 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 How to do that in the fish shell instead? 回答1: Fish doesn't support ranges in brace expansion, only comma-separated values: {a,b,c} . Thus, we are forced to search for a command capable of generating such sequence. For example, you can use Perl: for c in (perl -e '$,="\n"; print ("a" .. "z")') printf ">> %s\n" "$c" end where $, is the output field

How can I trigger brace expansion inside a script?

别等时光非礼了梦想. 提交于 2019-12-31 01:51:12
问题 I'm writing a script which needs to use the shell's brace expansion, but nothing I've tried works. For (a contrived) instance, say I have a variable containing the string thing{01..02} and I (obviously) want to expand it to thing01 thing02 from inside the script, how can I do that? (For anyone who assumes this is a duplicate of this other question, please read them more carefully. That question is regarding working from the shell, not a shell script, and doesn't require the ability to expand

how to use variables with brace expansion [duplicate]

☆樱花仙子☆ 提交于 2019-12-19 03:54:09
问题 This question already has answers here : Brace expansion with variable? [duplicate] (6 answers) Closed last year . I have four files: 1.txt 2.txt 3.txt 4.txt in linux shell, I could use : ls {1..4}.txt to list all the four files but if I set two variables : var1=1 and var2=4, how to list the four files? that is: var1=1 var2=4 ls {$var1..$var2}.txt # error what is the correct code? 回答1: Using variables with the sequence-expression form ( {<numFrom>..<numTo>} ) of brace expansion only works in

How to write fancy-indented multi-line brace expansion in Bash?

你说的曾经没有我的故事 提交于 2019-12-14 03:48:49
问题 I'm dealing with a line such : mkdir -p "$DEST_ROOT_PATH/"{"$DEST_DIR1","$DEST_DIR2", ..., "$DEST_DIRN"} This line is quite long. I want to cut it so its width will fit into a 80 columns line. I tried to escape an end of line with a backslash, but space alignement breaks the expansion : $ echo "ha"{a,b,\ > c} ha{a,b, c} 回答1: You could use this disgusting hack. echo "ha"{a,b,\ > ` `c} It opens a subshell with nothing in it, but gets processed before the expansion so the expansion just sees an

Multiply variable ranges with Bash brace expansion

折月煮酒 提交于 2019-12-11 10:53:10
问题 I've a question extending the code in this question: Can you multiply two variable ranges in Bash using brace expansion (not seq ) and not using loops? This is what I've tried so far Work out how variable boundary ranges work (finally, a good use of eval ): $ echo {1..10} 1 2 3 4 5 6 7 8 9 10 $ boundary=10 $ echo {1..$boundary} {1..10} $ eval echo {1..$boundary} 1 2 3 4 5 6 7 8 9 10 But how can you multiply two variable boundary ranges? $ echo $(({1..10}*{1..10})) 1 2 3 4 5 6 7 8 9 10 2 4 6 8

Bash bracket expansion: How to match all files names with a number?

蓝咒 提交于 2019-12-11 10:05:48
问题 I want to match all filenames in a directory that are like this: h1.txt, h2.txt, h12.txt, h3.txt If I do echo h[[:digit:]].txt I get h1.txt, h2.txt, h3.txt so it matches all the files I want, except h12.txt , because it has two digits instead of one. Is there an expansion for one or more digits? 回答1: Figured it out! echo h+([[:digit:]]).txt 来源: https://stackoverflow.com/questions/35433926/bash-bracket-expansion-how-to-match-all-files-names-with-a-number

Bash brace expansion not working on Dockerfile RUN command

旧巷老猫 提交于 2019-12-08 15:46:26
问题 I'm running the following RUN command in my Dockerfile, expecting a "logs" directory to be created under each of the listed subdirectories: RUN mkdir -p /opt/seagull/{diameter-env,h248-env,http-env,msrp-env,octcap-env,radius-env,sip-env,synchro-env,xcap-env}/logs But when I check the image, I see a directory literally called "{diameter-env,h248-env,http-env,msrp-env,octcap-env,radius-env,sip-env,synchro-env,xcap-env}" created under /opt/seagull, instead of brace expansion taking place. What

How can I make a multiplication table using bash brace expansion? So far I have this: echo $[{1..10}*{1..10}]

别说谁变了你拦得住时间么 提交于 2019-12-07 08:19:14
问题 I am trying to learn bash at a deeper level, and I decided to make a multiplication table. I have the functionality with the statement : echo $[{1..10}*{1..10}] but that gives me the following output: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 Is there any way

Understanding code ({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})

≡放荡痞女 提交于 2019-12-06 06:31:48
问题 I saw the following code in Bash shell Decimal to Binary conversion and I was wondering how it works? I tried googling with no avail. D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}) echo ${D2B[7]} What does the code above do? 回答1: {N..M} , for integer literals N and M, generates the series of integers from N to M, inclusively, separated by spaces. This is called a "brace expansion", and is a bashism. As you can see, all brace expansions are done before adding spaces between them.