brace-expansion

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

浪子不回头ぞ 提交于 2019-12-05 16:25:10
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 to format this output like the following using only 1 statement (i can figure out how to do this with

How to handle shell expansions in GNU Make under Ubuntu?

女生的网名这么多〃 提交于 2019-12-04 17:11:30
问题 Given this very simple Makefile : all: @mkdir -pv test/{a,b} I get this output on OS X 10.6.8 and CentOS 5.5: mkdir: created directory `test' mkdir: created directory `test/a' mkdir: created directory `test/b' But on Ubuntu 11.04 I get this: mkdir: created directory `test' mkdir: created directory `test/{a,b}' Running the command mkdir -pv test/{a,b} manually in the shell on all platforms gives the expected result. The version of GNU Make is the same on all platforms: GNU Make 3.81 Copyright

Powershell equivalent of Bash Brace Expansion for generating lists/arrays

蹲街弑〆低调 提交于 2019-12-03 06:06:25
When writing a Bash script you can use brace expansion to quickly generate lists: What is the simplest way to generate a similar list in Powershell? I can use the .. or , operators to generate an array , but how can I prefix the items with a static string literal? PS C:\Users\gb> 1..5 1 2 3 4 5 PS C:\Users\gb> "test"+1..5 test1 2 3 4 5 PS C:\Users\gb> "test","dev","prod" test dev prod PS C:\Users\gb> "asdf"+"test","dev","prod" asdftest dev prod PS C:\> "test","dev","prod" | % { "server-$_" } server-test server-dev server-prod PS C:\> 1..5 | % { "server{0:D2}" -f $_ } server01 server02 server03

Pattern expansion to run commands

被刻印的时光 ゝ 提交于 2019-12-02 05:04:25
问题 Knowing I am able to run echo or mv to expand patterns like these: echo {0..9}{A..Z} . I am curious to know if there is a way to do the same but to run commands? docker-compose {stop,rm,up -d} The example above does not work, but there is some way to accomplish that (to run stop, rm and up separately)? 回答1: You can use eval : eval docker-compose\ {stop,rm,'up -d'}\; Careful escaping/quoting is needed, though. Just test with echo instead of docker that it emits the correct commands: $ echo

How to generate letter sequence list in fish shell

匆匆过客 提交于 2019-12-02 00:06:54
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? 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 separator. Output >> a >> b ...(skipped) >> y >> z You may find this table useful. One way is to use printf and seq

how to use variables with brace expansion [duplicate]

你离开我真会死。 提交于 2019-11-30 22:12:46
This question already has an answer here: Brace expansion with variable? [duplicate] 6 answers 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? mklement0 Using variables with the sequence-expression form ( {<numFrom>..<numTo>} ) of brace expansion only works in ksh and zsh , but, unfortunately, not in bash (and (mostly) strictly POSIX-features-only shells such as dash do not

Brace expansion with range in fish shell

雨燕双飞 提交于 2019-11-30 06:24:06
In bash, I can do the following $ echo bunny{1..6} bunny1 bunny2 bunny3 bunny4 bunny5 bunny6 Is there a way to achieve the same result in fish? The short answer is echo bunny(seq 6) Longer answer: In keeping with fish's philosophy of replacing magical syntax with concrete commands, we should hunt for a Unix command that substitutes for the syntactic construct {1..6} . seq fits the bill; it outputs numbers in some range, and in this case, integers from 1 to 6. fish (to its shame) omits a help page for seq , but it is a standard Unix/Linux command. Once we have found such a command, we can

Tricky brace expansion in shell

瘦欲@ 提交于 2019-11-29 19:04:52
问题 When using a POSIX shell, the following touch {quick,man,strong}ly expands to touch quickly manly strongly Which will touch the files quickly , manly , and strongly , but is it possible to dynamically create the expansion? For example, the following illustrates what I want to do, but does not work because of the order of expansion: TEST=quick,man,strong #possibly output from a program echo {$TEST}ly Is there any way to achieve this? I do not mind constricting myself to Bash if need be. I

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

前提是你 提交于 2019-11-29 02:47:59
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? 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. Because brace expansion occurs before expansion of variables. http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion . If you want to use braces, you could so

Brace expansion with range in fish shell

橙三吉。 提交于 2019-11-29 01:45:50
问题 In bash, I can do the following $ echo bunny{1..6} bunny1 bunny2 bunny3 bunny4 bunny5 bunny6 Is there a way to achieve the same result in fish? 回答1: The short answer is echo bunny(seq 6) Longer answer: In keeping with fish's philosophy of replacing magical syntax with concrete commands, we should hunt for a Unix command that substitutes for the syntactic construct {1..6} . seq fits the bill; it outputs numbers in some range, and in this case, integers from 1 to 6. fish (to its shame) omits a