variable-expansion

Passing a command with arguments as a string to docker run

跟風遠走 提交于 2021-01-27 04:12:07
问题 The issue I'm facing is how to pass a command with arguments to docker run . The problem is that docker run does not take command plus arguments as a single string. They need to be provided as individual first-class arguments to docker run , such as: #!/bin/bash docker run --rm -it myImage bash -c "(cd build && make)" However consider the command and argument as the value of a variable: #!/bin/bash -x DOCKER_COMMAND='bash -c "(cd build && make)"' docker run --rm -it myImage "$DOCKER_COMMAND"

Bash arbitrary glob pattern (with spaces) in for loop

青春壹個敷衍的年華 提交于 2020-06-08 17:05:32
问题 Is there any way to reliably use an arbitrary globbing pattern that's stored in a variable? I'm having difficulty if the pattern contains both spaces and metacharacters. Here's what I mean. If I have a pattern stored in a variable without spaces, things seem to work just fine: <prompt> touch aa.{1,2,3} "a b".{1,2,3} <prompt> p="aa.?" <prompt> for f in ${p} ; do echo "|$f|" ; done |aa.1| |aa.2| |aa.3| <prompt> declare -a A=($p) ; for f in "${A[@]}" ; do echo "|$f|" ; done |aa.1| |aa.2| |aa.3|

How to obtain the first letter in a Bash variable?

眉间皱痕 提交于 2020-01-28 04:22:07
问题 I have a Bash variable, $word , which is sometimes a word or sentence, e.g.: word="tiger" Or: word="This is a sentence." How can I make a new Bash variable which is equal to only the first letter found in the variable? E.g., the above would be: echo $firstletter t Or: echo $firstletter T 回答1: initial="$(echo $word | head -c 1)" Every time you say "first" in your problem description, head is a likely solution. 回答2: word="tiger" firstletter=${word:0:1} 回答3: word=something first=${word::1} 回答4:

How do I delay expansion of variables in PowerShell strings?

倖福魔咒の 提交于 2020-01-09 11:12:50
问题 Whatever you want to call it, I'm trying to figure out a way to take the contents of an existing string and evaluate them as a double-quoted string. For example, if I create the following strings: $string = 'The $animal says "meow"' $animal = 'cat' Then, Write-Host $string would produce The $animal says "meow" . How can I have $string re-evaluated, to output (or assign to a new variable) The cat says "meow" ? How annoying...the limitations on comments makes it very difficult (if it's even

Using Groovy for variable expansion in Java properties

£可爱£侵袭症+ 提交于 2020-01-03 18:59:13
问题 I frequently use standard Java property files for configuring my Groovy applications. One feature I have been missing is the ability to use variables as part of the property value so they can be expand dynamically during use. I thought I could provide this functionality using the following design: Use a special format to annotate the properties that should be expanded. I have chosen to enclose such templates in double exclamation marks (!!). These property values are essentially a template to

How to do a partial expand in Snakemake?

感情迁移 提交于 2019-12-30 10:32:47
问题 I'm trying to first generate 4 files, for the LETTERS x NUMS combinations, then summarize over the NUMS to obtain one file per element in LETTERS: LETTERS = ["A", "B"] NUMS = ["1", "2"] rule all: input: expand("combined_{letter}.txt", letter=LETTERS) rule generate_text: output: "text_{letter}_{num}.txt" shell: """ echo "test" > {output} """ rule combine text: input: expand("text_{letter}_{num}.txt", num=NUMS) output: "combined_{letter}.txt" shell: """ cat {input} > {output} """ Executing this

How to do a partial expand in Snakemake?

不打扰是莪最后的温柔 提交于 2019-12-30 10:32:00
问题 I'm trying to first generate 4 files, for the LETTERS x NUMS combinations, then summarize over the NUMS to obtain one file per element in LETTERS: LETTERS = ["A", "B"] NUMS = ["1", "2"] rule all: input: expand("combined_{letter}.txt", letter=LETTERS) rule generate_text: output: "text_{letter}_{num}.txt" shell: """ echo "test" > {output} """ rule combine text: input: expand("text_{letter}_{num}.txt", num=NUMS) output: "combined_{letter}.txt" shell: """ cat {input} > {output} """ Executing this

Performance of variable expansion vs. sprintf in PHP

蹲街弑〆低调 提交于 2019-12-28 06:42:05
问题 Regarding performance, is there any difference between doing: $message = "The request $request has $n errors"; and $message = sprintf('The request %s has %d errors', $request, $n); in PHP? I would say that calling a function involves more stuff, but I do not know what's PHP doing behind the scenes to expand variables names. Thanks! 回答1: In all cases the second won't be faster, since you are supplying a double-quoted string, which have to be parsed for variables as well. If you are going for

Performance of variable expansion vs. sprintf in PHP

一笑奈何 提交于 2019-12-28 06:41:11
问题 Regarding performance, is there any difference between doing: $message = "The request $request has $n errors"; and $message = sprintf('The request %s has %d errors', $request, $n); in PHP? I would say that calling a function involves more stuff, but I do not know what's PHP doing behind the scenes to expand variables names. Thanks! 回答1: In all cases the second won't be faster, since you are supplying a double-quoted string, which have to be parsed for variables as well. If you are going for

Parameter expansion for find command

筅森魡賤 提交于 2019-12-24 00:24:37
问题 Consider the code (the variable $i is there because it was in a loop, adding several conditions to the pattern, e.g. *.a and *.b , ... but to illustrate this problem only one wildcard pattern is enough): #!/bin/bash i="a" PATTERN="-name bar -or -name *.$i" find . \( $PATTERN \) If ran on a folder containing files bar and foo.a , it works, outputting: ./foo.a ./bar But if you now add a new file to the folder, namely zoo.a , then it no longer works: find: paths must precede expression: zoo.a