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
0
votes
1 answer

How to expand only bash a specific $variable at any certain point

How to expand only bash $variable at any certain point of anything (time, condition, etc) ? as this works : i=1 u="sum = $i + \$o" o=two; n=$(eval echo $u) to equalize to n='sum = 1 + two' the truth, $(eval echo $) won't work for complex…
user15148997
0
votes
1 answer

Environment variable expansion not longer works in npm run on Windows

I have npm scripts that use environment variables. Here is an excerpt of package.json: "scripts": { "staging": "npm run deploy -env=staging", "deploy": "winrs /r:intranet /d:F:\\wwwintranet\\deploy npm run build…
0
votes
1 answer

Shell: Expand $HOME from regular file

I'm storing commands in a file to be read and run line by line by a POSIX shell program. It looks something like this: curl -fLo $HOME/.antigen.zsh git.io/antigen curl -fLo $HOME/.vim/autoload/plug.vim --create-dirs…
Groctel
  • 130
  • 11
0
votes
1 answer

Case statement for optional parameters not expanding some variable

Based on this answer I wrote some simple optional argument parser #!/bin/bash TEST_PATH=pluto if [ $# -eq 0 ]; then echo "Usage:" echo "./run.sh [--valgrind|-v] [--test|-t] " else . config.sh while [[ "$#"…
Eugenio
  • 244
  • 2
  • 13
0
votes
2 answers

Evaluate variable at time of function declaration in shell

I'm setting up my shell environments and I want to be able to use some of the same functions/aliases in zsh as in bash. One of these functions opens either .bashrc or .zshrc in an editor (whichever file is relevant), waits for the editor to close,…
dx_over_dt
  • 13,240
  • 17
  • 54
  • 102
0
votes
2 answers

assign and expand shell variable in same command line

I want to assign one or multiple variables at the beginning of a command line in my shell to reuse it in the command invocation. I'm confused of how my shell behaves and want to understand what is happening. I'm using ZSH but am also interested what…
Thomas Koch
  • 2,833
  • 2
  • 28
  • 36
0
votes
0 answers

Trying to run multiple processes in bash only executes one time

I have the following in my bash file: echo "Spawning $1 processes" for i in {1..$1} do (go run loadgen.go $2 &) echo "done." done However, I can only seem to get my go file to execute once. I know that they're started in the background, but…
MrDuk
  • 16,578
  • 18
  • 74
  • 133
0
votes
1 answer

How to expand a variable that contains a mixture of text and other variables?

I am writing an script and I need to locate the desktop folder of the current user. I want it to be language-independent so I found that on Ubuntu you can find the path of the desktop (independently of the system language) in…
0
votes
0 answers

bash/ cat with ${} doesn't work as expected it to go

Problem. directory=mac/1.x.x/** even though mac/1.x.x/**/*.sql is right path, cat ${directory}/*.sql the command above said No such file or directory . and I want to make that possible. What I tried. to check the path is right, I did cat…
0
votes
1 answer

Why would bash variables not expand in while loop

I have a little script that reads a json file: { "path": "$HOME/Projects:$HOME/Github" } I want to read path value, split on colon : and then read out the two paths with $HOME expanded. #!/bin/sh path_list="$(jq -r '.path' < "$JSON_FILE" | tr…
Jeff
  • 2,293
  • 4
  • 26
  • 43
0
votes
1 answer

Passing CFLAGS to configure via bash variable

Just when I think I know how the shell works fairly, something comes along and stumps me. The following commands were executed on GNU bash, version 3.2.25. I have several ./configure scripts that all share a group of common configure options, one of…
Tyg13
  • 321
  • 2
  • 10
0
votes
2 answers

Why does assigning result of a map function to one variable differs from assigning it to several variables?

Here I have input 2 strings "12" and "123 54 856 78 " to the same function but one gets converted to int while other doesn't: str="12" a=map(int,str.split()) print(type(a)) #o/p : print (a) #o/p :
0
votes
0 answers

Can bash treat $VAR as "$VAR"?

Given a variable VAR, that may contain an empty string, is it possible to make bash always interpret both ls $VAR ls "$VAR" as "command that is given one argument"? For bash, the IFS variable allows determining how the unquoted variable expansion…
kdb
  • 4,098
  • 26
  • 49
0
votes
1 answer

Local variable in makefile is not expanded correctly

I have the following function in makefile: define INSTALL_SCRIPT SRC_DIR = $(ROOT)\src cd $(SRC_DIR) $(SRC_DIR)\stage.bat endef I also echo the steps, so here's the output of the above snippet: $SRC_DIR = C:\project_root\src 'SRC_DIR' is not…
user3132457
  • 789
  • 2
  • 11
  • 29
0
votes
0 answers

Bash variable expansion inside array

How to pass the value from variable inside the array list. The below code works, it assigns the repo_libs elements to repo_list. Is there a way to read the value from variable to form the array name inside the array list. if [[ "$service" == "all"…
intechops6
  • 1,007
  • 4
  • 22
  • 43