expansion

Sequences expansion and variable in bash [duplicate]

血红的双手。 提交于 2019-11-27 09:30:26
This question already has an answer here: Brace expansion with variable? [duplicate] 6 answers I am having a problem with builtin sequences (ie: not using seq) in Bash when the seq number is a variable. For example, this works and print me 1 2 3: for i in {1..3};do echo $i;done but this : bash-3.2$ a=3;for i in {1..$a};do echo $i;done fail and print me {1..3} only This works with ZSH and I know I have an alternative to make a counter thing but wondering if this is a bug or a brace expansion feature! In Bash, brace expansion is performed before variable expansion. See Shell Expansions for the

Loop over array, preventing wildcard expansion (*)

核能气质少年 提交于 2019-11-27 07:03:32
问题 I'm trying to figure out what I thought would be a trivial issue in BASH, but I'm having difficulty finding the correct syntax. I want to loop over an array of values, one of them being an asterisk (*), I do not wish to have any wildcard expansion happening during the process. WHITELIST_DOMAINS="* *.foo.com *.bar.com" for domain in $WHITELIST_DOMAINS do echo "$domain" done I have the above, and I'm trying to get the following output: * *.foo.com *.bar.com Instead of the above, I get a

Why $'\0' or $'\x0' is an empty string? Should be the null-character, isn't it?

你离开我真会死。 提交于 2019-11-27 01:07:46
问题 bash allows $' string ' expansion. My man bash says: Words of the form $' string ' are treated specially. The word expands to string , with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: \a alert (bell) \b backspace \e \E an escape character \f form feed \n new line \r carriage return \t horizontal tab \v vertical tab \ backslash \' single quote \" double quote \ nnn the eight-bit character whose value

Sequences expansion and variable in bash [duplicate]

ぃ、小莉子 提交于 2019-11-26 14:43:56
问题 This question already has an answer here: Brace expansion with variable? [duplicate] 6 answers I am having a problem with builtin sequences (ie: not using seq) in Bash when the seq number is a variable. For example, this works and print me 1 2 3: for i in {1..3};do echo $i;done but this : bash-3.2$ a=3;for i in {1..$a};do echo $i;done fail and print me {1..3} only This works with ZSH and I know I have an alternative to make a counter thing but wondering if this is a bug or a brace expansion

Base64: What is the worst possible increase in space usage?

删除回忆录丶 提交于 2019-11-26 01:40:05
问题 If a server received a base64 string and wanted to check it\'s length before converting,, say it wanted to always permit the final byte array to be 16KB. How big could a 16KB byte array possibly become when converted to a Base64 string (assuming one byte per character)? 回答1: Base64 encodes each set of three bytes into four bytes. In addition the output is padded to always be a multiple of four. This means that the size of the base-64 representation of a string of size n is: ceil(n / 3) * 4 So

Why does shell ignore quotes in arguments passed to it through variables? [duplicate]

余生长醉 提交于 2019-11-25 21:46:12
问题 This question already has answers here : How to store a command in a variable in a shell script? (6 answers) Closed 10 months ago . This works as advertised: # example 1 #!/bin/bash grep -ir \'hello world\' . This doesn\'t: # example 2 #!/bin/bash argumentString=\"-ir \'hello world\'\" grep $argumentString . Despite \'hello world\' being enclosed by quotes in the second example, grep interprets \'hello as one argument and world\' as another, which means that, in this case, \'hello will be the

Base64: What is the worst possible increase in space usage?

若如初见. 提交于 2019-11-25 19:25:40
If a server received a base64 string and wanted to check it's length before converting,, say it wanted to always permit the final byte array to be 16KB. How big could a 16KB byte array possibly become when converted to a Base64 string (assuming one byte per character)? R. Martinho Fernandes Base64 encodes each set of three bytes into four bytes. In addition the output is padded to always be a multiple of four. This means that the size of the base-64 representation of a string of size n is: ceil(n / 3) * 4 So, for a 16kB array, the base-64 representation will be ceil(16*1024/3)*4 = 21848 bytes