Questions tagged [variable-expansion]

Evaluating or expanding a variable to get its value. Depending on the language, a variable may be expanded one or more times.

246 questions
2
votes
1 answer

Batch file FOR/f expansion

I have a file (directories.txt) with directory names, each on a single line and I like to expand the line C:\Documents and Settings\%USERNAME%\My Documents In my script to the real user name running the script. However the echo comes out exactly…
Janco
  • 1,130
  • 1
  • 8
  • 15
2
votes
1 answer

bash expanding value of a variable to use in another variable

I hope the question makes sense, I would like to do something like: a=test b=a echo ${$b} # should echo test Basically I'd like $b to expand to the value a and have bash echo out the value of variable $a (since ${a} is test). What syntax should I…
Andreas Wong
  • 59,630
  • 19
  • 106
  • 123
1
vote
3 answers

Bash script parameter expansion

I have a script: #!/bin/bash SINGLE_FILE=/tmp/blah.file MULTIPLE_FILES=/tmp/{dir1,dir2}/*.file cp $SINGLE_FILE $MULTIPLE_FILES /tmp/newDir This will fail with: cp: cannot stat `/tmp/{dir1,dir2}/*.file': No such file or directory It looks like…
Kevin S
  • 2,713
  • 24
  • 31
1
vote
1 answer

Baffling Zsh behavior on = (equal sign) precedes a Zsh $variable

When a = sign precedes a Zsh $variable expansion, I get the following behavior: % m=$PATH; echo =$m= zsh: /usr/local/bin:/usr/sbin:/usr/bin= not found Quite perplexing. What is happening, and why?
1
vote
1 answer

how to print range of numbers by using passing value to variable from 1 to $num with echo command?

I want to print all the integer value from 1 to 10 by using echo {1..$num} and i want to used it pdftk If i do with echo {1..10} it is printing what i exactly want, but i want to pass a value to some variable and that variable below is my MWE. …
Biki Teron
  • 237
  • 2
  • 4
  • 12
1
vote
0 answers

Conditionally add debug flags when building a Go program

I'm writing a Makefile for a Go application, and would like to be able to pass in an environment variable to specify debug flags for the go build command. The script for building the service without debug flags looks like this: cd…
Harrison Cramer
  • 3,792
  • 9
  • 33
  • 61
1
vote
6 answers

how to extract part of URL in bash using regx?

I am trying to extract part of url using bash regex . from below mentioned URL i just want to extract 124, which will always be between two hyphens . http://abc-124-001.portal-ex.xyz-xyz.com:8091/ i tried doing following but i am looking for any…
deewreck
  • 113
  • 7
1
vote
1 answer

Bash - Expanding variables for command arguments leads to quoting hell

So, I'm scripting an rsync command. I've been fiddling around for the entire day. It's time to ask for help. My issue appears to be quoting, but it's not obvious to me exactly what's going wrong. This snippet: #!/bin/bash sudo -v COMMAND=`basename…
Aaron
  • 675
  • 6
  • 12
1
vote
1 answer

Using "expanding characters" in a variable in a bash script

I apologize beforehand for this question, which is probably both ill formulated and answered a thousand times over. I get the feeling that my inability to find an answer is that I don't quite know how to ask the question. I'm writing a script that…
DanielSmedegaardBuus
  • 977
  • 1
  • 10
  • 18
1
vote
1 answer

Simplify debugging output. Specific request for in-place command text replacement in BASH

OK, so, I have a debugging setup a little like this: DVAR=(); function DBG() { if [[ $1 == -s ]]; then shift; stackTrace; fi; if [[ ! -z ${DVAR[@]} ]]; then for _v in ${!DVAR[@]}; do echo "${DVAR[$_v]}" >> $LOG; …
BenG
  • 31
  • 5
1
vote
1 answer

Correctly consuming a multiline config file in snakemake as an input

For various reasons I would like to be able to define my inputs in a separate config file. My current version without using a config file looks like: rule test: input: labs = "data/labs.csv" demo = "data/demo.csv" output: …
1
vote
3 answers

Expand bash array with globbing and extra words

In a CI/CD job, I have a shell variable X defined. It contains one or more words, each of which might have glob operators: X="foo bar* 'a b c'" Suppose bar* matches 3 files, bard, bare, and barf. And the file a b c exists and has 2 spaces in…
Ken Williams
  • 22,756
  • 10
  • 85
  • 147
1
vote
5 answers

Variable expansion not working as expected in Azure DevOps Yaml Pipeline when stages are associated with different variable groups

I receive the error message 'Job Job1: Environment $(environmentName) could not be found. The environment does not exist or has not been authorized for use.' when I run the pipeline below. trigger: - main pool: vmImage: ubuntu-latest stages: …
1
vote
1 answer

How can I suppress zsh pattern escaping during string expansion?

I am trying to port this snippet of code from bash to zsh: #! /usr/bin/env bash # change zsh set -x pattern="[ab]" marks="a" case "${marks}" in ${pattern}) echo match ;; esac This prints "match". Bash replaces ${pattern} as is and…
user3093235
  • 397
  • 2
  • 12
1
vote
4 answers

Parse variables out of a "key1='val1' key2='val2'" string in bash without eval

I have one project specific command which produces output in the below form: Parameter1='value1' Parameter2='Value2' ... #Single quoted value for the variable. But I wanted to explicitly assign the value and needed to print the parameters which…