variable-expansion Questions
35
Solved
Or more generally, how do I remove an item from a colon-separated list in a Bash environment variable?
I thought I had seen a simple way to do this years ago, using the more advanced forms of Bash...
Haubergeon asked 15/12, 2008 at 23:19
3
Html portion
$html = @($htm)
$html = @"
<!doctype html>
<html lang="en">
<head>
<body>
text
$computername
$username
text
</body>
</html>
"...
Schindler asked 3/10, 2023 at 11:47
7
Solved
#!/bin/sh
for i in {1..5}
do
echo "Welcome"
done
Would work, displays Welcome 5 times.
#!/bin/sh
howmany=`grep -c $1 /root/file`
for i in {1..$howmany}
do
echo "Welcome"
done
Doesn't w...
Swaim asked 17/10, 2013 at 16:54
3
Solved
So I have a bash script that is generating a string of commands that I want to be run. The output looks something like
$ program "command1 command2 ... commandN"
But the program is interpreting ...
Lymphatic asked 5/5, 2015 at 19:31
5
Solved
In Bash scripts, I frequently find this pattern useful, where I first print the command I'm about to execute, then I execute the command:
echo 'Running this cmd: ls -1 "$HOME/temp/some folder ...
Airt asked 14/2, 2022 at 20:31
3
Solved
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...
Photocathode asked 3/11, 2016 at 9:37
4
Solved
(edit: question more accurate based on @Michael feedback)
In bash, I often use parameter expansion: the following commands print "default value" when $VARNAME is unset, otherwise it prints the VAR...
Pear asked 16/4, 2013 at 10:54
3
Solved
For debugging my scripts, I would like to add the internal variables $FUNCNAME and $LINENO at the beginning of each of my outputs, so I know what function and line number the output occurs on.
foo...
Paracasein asked 25/5, 2018 at 21:30
1
Solved
With multiple variables beginning with the same pattern can a wildcard be used to echo all matched patterns?
when zzz1=test1; zzz_A=test2; zzza=test3
What is the best way to match all variables s...
Alcibiades asked 23/11, 2019 at 12:40
6
Solved
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...
Botulism asked 22/8, 2011 at 12:14
2
Solved
Is it possible to do nested parameter expansion in bash? (e.g.: VAR=${{1:-$ENV_VAR}:-hard-coded default})
I want to set command line arguments with default values. However, before using a hard-cod...
Proto asked 25/4, 2019 at 14:13
7
Solved
In shell scripts, when do we use {} when expanding variables?
For example, I have seen the following:
var=10 # Declare variable
echo "${var}" # One use of the variable
echo "$var" # Another use ...
Sefton asked 5/1, 2012 at 19:54
1
Solved
From FOR /?:
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - e...
Trichinosis asked 1/11, 2018 at 3:32
7
Solved
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 let...
Goldsmith asked 18/4, 2012 at 21:42
2
Solved
I'm trying to write a function that will print a user-supplied greeting addressed to a user-supplied name. I want to use expanding strings the way I can in this code block:
$Name = "World"
$Gree...
Obstruct asked 27/7, 2018 at 10:6
5
Solved
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:
...
Killen asked 1/3, 2013 at 23:36
1
Solved
I'm going through a Bash tutorial, and specifically the subject of word splitting.
This script, called "args", helps demonstrate word splitting examples:
#!/usr/bin/env bash
printf "%d args:" $#
...
Glory asked 1/4, 2017 at 23:54
1
Solved
I have a code block with below condition, not sure what exactly it does.
$var = "${args}_Some_Text"
if [ "${!var}" == '' ];then
echo "$var is not defined !!!"
fi
Mirellamirelle asked 2/12, 2016 at 9:13
1
Solved
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 indiv...
Trichotomy asked 12/9, 2016 at 5:36
1
Solved
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 ex...
Unfeeling asked 19/8, 2016 at 11:59
3
Solved
I'm trying to split a json file into various json files. The input (r1.json) looks like :
{
"results" : [
{
content 1
}
,
{
content 2
}
,
{
content n
}
]
}
I'd like the output to be n...
Phocomelia asked 23/12, 2015 at 0:47
1
Solved
When I try to passing arguments as variables to any commands in bash I can see extra quotes added by bash if the variable value has spaces.
I am creating a file "some file.txt" and adding it to a...
Enphytotic asked 23/11, 2015 at 12:49
2
Solved
I'm using the following git command in git bash on Windows:
git log --format="%C(cyan)%cd%Creset %s" --date=short -5
It displays commit date (%cd) followed by commit message (%s). Commit date is...
Lamoreaux asked 8/10, 2015 at 12:40
2
Inside of a while read line loop, I see this variable expansion ${line/device name:}. I've tried running the script with my own input file and it just prints out the line.
Can you tell me what th...
Thirsty asked 16/9, 2015 at 22:19
2
Solved
How can I expand $pw inside single quotes?
$pw = "$PsHome\powershell.exe"
cmd.exe /c 'schtasks /create /tn cleanup /tr "$pw -WindowStyle hidden -ExecutionPolicy Bypass -nologo -noprofile %TEMP%\ex...
Bullish asked 20/8, 2015 at 20:18
1 Next >
© 2022 - 2024 — McMap. All rights reserved.