Questions tagged [variable-substitution]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
2 answers
43 views

sed and variables-substitutions on an custom script

well i ask here because i have around 12 hours trying with examples on internet for put a replace with sed on a custom script. In the file a had a lots of lines but i want to replace values after &...
user avatar
  • 29
-1 votes
1 answer
30 views

How is the match evaluated in parameter expansion in bash?

I read "Linux Bible 10th Edition", chapter 7: Writing Simple Shell Scripts, at 149 page, "Parameter expansion in bash" paragraph. ${var:-value} — If variable is unset or empty, ...
user avatar
  • 135
0 votes
1 answer
24 views

Find with optional parenthesised arguments

How to add optional grouped argument lists to find? For example, using an array of base arguments that define files that will always be found, no matter what other variable conditions are specified. # ...
user avatar
  • 147
0 votes
2 answers
13 views

Putting variables in cardano-wallet function in terminal

How to enable variables in terminal to be changeable, for example address, I would like to be able to run this function through for loop in terminal with different addresses.
user avatar
0 votes
2 answers
34 views

When looking at subdirectories, skip one directory

I have a directory /u01/oracle/folders with these subfolders: [root@ricusesasctl01vm tax_receipts]# ls -ltr total 64 drwxr-xr-x 5 OICDev1 oic 4096 Mar 1 2021 Argentina drwxr-xr-x 5 OICDev1 oic 4096 ...
user avatar
0 votes
0 answers
19 views

Something in the file is messing with ZSH [duplicate]

I have a file with such lines: map_Kn Ellie_Caruncle_N.png I'm trying to extract field #2, and use it twice in a command like this, but it's giving me some problems. Here is a ZSH session: ~/Downloads/...
user avatar
  • 1,469
0 votes
1 answer
37 views

Using Pipes to Generate Variable for Execution

I have the following test case that I am trying to work with: countAlpha=10;bob=alpha; echo $(echo $bob | sed 's/[a-z]/\U&/; s/^/\$count/') $countAlpha Which produces the following: $countAlpha ...
user avatar
0 votes
0 answers
18 views

cd command to a variable containing a path with spaces gives different output than actually giving the path as an input [duplicate]

I have a directory named "test 1" and I create a variable dest="test\ 1" I want to navigate to the directory using the cd command, so I type cd $dest which gives the output as -...
user avatar
0 votes
0 answers
24 views

AWS Athena Query execution from shell script faild

I am working with AWS Athena with Shell Script. My requirement is to create an Athena table from a shell script execution. I am able to delete table through shell script Create table query have a ...
user avatar
0 votes
0 answers
49 views

how to expand a variable with backslash in bash script [duplicate]

i read a line from another file that contains a backslash, and i want to echo this line without expanding the backslash : script.sh : #!/bin/bash while read line do echo "$line" done &...
user avatar
  • 111
0 votes
2 answers
24 views

Can the list if the variable used in a for loop be made up of variables themselves?

I'm trying to create a script where pretty much things got sorted out earlier in it and I'm left with the booleans I need stored in variables. I just need to run them through one last loop and I'm ...
user avatar
  • 93
0 votes
1 answer
30 views

passing arguments to a command run by su

I want to run a command as a different user (the current user is root). Thus, I do su newuser -c 'mkdir "/tmp/test"' but I have a problem in passing arguments to it i="name" su ...
user avatar
  • 1,663
1 vote
1 answer
90 views

How to store '>&2' in a variable

Similar question, but no answer: How can we run a command stored in a variable? How to do the following in bash script? error=">&2" echo 'something went wrong' $error instead of echo ...
user avatar
  • 15
0 votes
0 answers
13 views

How to substitute a variable in a composed bash command sequence? [duplicate]

My command is as follows: docker rm -f $(docker ps -a --filter 'ancestor=user/$INSTALLATION_NAME' --format="{{.ID}}") where $INSTALLATION_NAME is set with the $HOSTNAME variable (simulate ...
user avatar
0 votes
1 answer
57 views

Printing a shell variable yields empty output

I have the following program where I want to print a variable $var that I fill with the execution time of a program. However, when outputting it to the console with echo or printf the value is empty. ...
user avatar
  • 3
1 vote
3 answers
408 views

Bash interpreting a variable assignment as a command

I've been trying to do something for a couple of days, and I'm stumped; I keep running into the same problem, no matter how I approach this. I have a text file with 2 columns in it; the first is the ...
user avatar
  • 113
1 vote
2 answers
134 views

Asterisk/Double Quote Failing to Excecute

Sory I'm new to shellscripting. I have a variable that contains an option related to find command. TYPE=("-type f") NAME=("-name \"*log*\"") I try put those variable ...
user avatar
1 vote
0 answers
35 views

zsh: Make getting the value of a variable invoke a function

I like to use a "getter" function for some variable foo, such that using "$foo" is equivalent to "$(foo-getter)". It think this should be possible, as $EPOCHREALTIME ...
user avatar
  • 1,287
1 vote
1 answer
562 views

How to deal with special characters in docker registry credential in new version of kubectl

Today I want to add a docker registry credential in kubernetes v1.21.3 (it works fine in lower version of kubernetes but have problem in new version of kubernetes): kubectl create secret docker-...
user avatar
  • 339
1 vote
1 answer
87 views

Unable to use a variable to specify the targets for rsync's "--exclude={..}" option within script

My goal is to have my bash script run this command: rsync -azhi --dry-run --exclude={'file1.txt','file2.txt','*.sql'} /from-directory/ /to-directory/ ... when abstracted thusly: srcdir='/from-...
user avatar
0 votes
2 answers
144 views

How to a split string by spaces, which contains quoted values

Take the following bash example (I should mention that my real output comes from vboxmanage list vms) TEST='"ubuntu server" foo bar' echo $TEST "ubuntu server" foo bar How do I ...
user avatar
  • 103
4 votes
2 answers
361 views

Keep matching pattern in shell parameter expansion

I can remove a pattern in a bash variable using ${variable##pattern} (leading) or ${variable%%pattern} (trailing). But I can't find a bash-only way to keep the pattern and throw the rest. I know there ...
user avatar
  • 7,834
2 votes
2 answers
164 views

awk evaluate variable in statement

I am new to awk, I tried numerous suggestion found online, but I cannot resolve my problem. I need variable $number to get evaluated inside the -F arg value. This statement works as expected: inn=$(ip ...
user avatar
  • 123
1 vote
1 answer
64 views

Error while executing "sed" command that uses shell variables

This has been driving me crazy... I want to list files in a dir and, based on the number interate on all files except the latest one, here is the code snipplet FILECOUNT=$(ls -lt [dir]*.log | grep -c ...
user avatar
  • 13
3 votes
1 answer
281 views

Bash Script : Problem with variables from csv file

I'm having a little problem getting variables from a csv file on my Linux machine and using them in an if. I have the following csv: Name;Age Marc;18 Joseph;10 I'm trying to get this information from ...
user avatar
3 votes
1 answer
433 views

Grep pattern that has double quotes and variable substitution surrounded by single quotes

So, Let's say I have the following pattern: Thisisatest="1" in a file called file. And I want to match the exact string above but for whatever reason, I choose to loop over some numbers ...
user avatar
1 vote
2 answers
427 views

Pass the variable value to curl JSON

I am trying to create a JIRA ticket using curl POST method, but the variable substitution is not happening properly in TODAY_DATE variable. If i remove that it is working fine. ANy hint on how this ...
user avatar
0 votes
1 answer
106 views

Nested variables that rely on one another

I'm trying to automate WireGuard on my OpenWrt router but I'm having some issues with nested variables when it comes to creating my configuration file. Below are the variables I have set: export LAN=&...
user avatar
1 vote
1 answer
219 views

Shell Parameter expansion not working in AIX

I'm trying to substitute a specific string that isn't working in AIX but when I run it on RHEL I'm able to get the expected output. Here's the command: filename=25_032021_abcdefghijklmn.txt; mv /u/foo/...
user avatar
  • 13
0 votes
2 answers
312 views

sed with external script file - How to apply shell variables?

Directly on the command line, this works: $sed "s/a/X/;s/X/&a&/" file and so does using shell variables: $varin=a ; varout=X ; sed "s/$varin/$varout/;s/$varout/&$varin&/...
user avatar
  • 10.6k
1 vote
1 answer
77 views

Zsh: How to make `${x:?}` return non-zero in case of empty `$x`?

How to make ${x:?} return non-zero in case of empty $x? By default, it exits the shell (subshell in this example) with 0. function sth() { local url="${1:?}" ... } (sth) ; echo $? # ...
user avatar
  • 1,287
3 votes
2 answers
201 views

zsh syntax to expand variables' names matching a prefix

TL; DR: is there a zsh equivalent of Ksh/Bash's "${!varnamepfx@}" expansion? So that, for example, if I have the following variables set: [...] foo='random value' bar=$'amazing\n value' baz='...
user avatar
  • 4,269
2 votes
1 answer
211 views

Is there a way to expand a variable into multiple arguments without globbing in bash? [duplicate]

I would like to define an expression for find which includes a wildcard in a -name subexpression: find_expression="-type f -name *.csv -mtime +14" And then use it in a couple of places ...
user avatar
3 votes
1 answer
507 views

bash: one parameter substitution: beginning and end of string

This question is not about how to accomplish this with sed, grep or similar tools. Please don't answer with those. I have a string (it can be any string along the same structure foofoo_barbar, etc): ...
user avatar
0 votes
1 answer
115 views

Variable in Bash Alias not working as intended [duplicate]

The alias doesn't work properly until running source ~/.bashrc or source ~/.bash_aliases ONLY AFTER running the alias once first. Is there a magical way to get the $todaydir string to be replaced ...
user avatar
0 votes
1 answer
82 views

Creating directories inside a directory, from variable values, to redirect output from sed

I am trying to take a file, modify this file by using a value from a for loop (using sed) and redirecting it to a directory that has been created during the same for loop. Original file > Make ...
user avatar
  • 5
0 votes
2 answers
75 views

parameter expansion in file insted of cut

I wanted to do cut string on last delimiter using parameter expansion. name='ls $(Build.ArtifactStagingDirectory)/drop/abc.jar' string1="${name%/*}" string2="${name##*/}" echo &...
user avatar
0 votes
3 answers
41 views

How to subsitute contents of a file contained within the output of a variable

I have searched for variable syntax and other commands but I cannot get through. I have some folders created with btrfs snapshots. Within each folder there is a file called /etc/fstab that I need to ...
user avatar
  • 1
0 votes
3 answers
706 views

How do i use variable's value as a dynamic variable name?

i've been looking around for this all over, but either i don't know how to ask the question correctly, or it's not a common enough issue... In PHP this is (almost) trivial: function getSite(string $...
user avatar
0 votes
1 answer
107 views

Expand shell variable while editing command line

If I write ls bla.* at the prompt and then I press = while the cursor is still on the bla.* part of the command line, the list of files matching bla.* is printed. If I press *, that word is ...
user avatar
  • 1,012
0 votes
0 answers
16 views

assign to a number named variable to mimic command line argument [duplicate]

I have a script where I am passing commands to processes with an arguments passed from command line and from environment variables as well. To simplify my use case lets assume my processes are echo ...
user avatar
1 vote
1 answer
1k views

How to output comma separated values using IFS="," in shell [duplicate]

I have a small script, which does not give comma separated output when IFS is used, but IFS is mandatory as i need it to read many other value. The output of the below script is odi_server1 ...
user avatar
0 votes
4 answers
283 views

Bash ls with double substitution

I am writing a bash script that reads a directory from the command line arguments and performs an ls on it. If I specify a simple directory, then all is OK. But I want do something like /home/{x,y}, ...
user avatar
0 votes
3 answers
707 views

Not able to get the values in JSON from Variable

I have written small Shell/bash script, where I have some data in sampleData.txt file which I want to convert in Base64 and to pass it in variable $scriptPayload: value=$(cat sampleData.txt) echo &...
user avatar
  • 1
4 votes
0 answers
72 views

${$} working fine in ksh93 but ${$} not working when I use in cat << EOF

I'm executing this in the ksh93 shell. If I use normally like ~# echo ${$} 1295 but using ${$} in a here-document is not working: ~#cat <<EOF ~#> ${$} ~#> EOF syntax error: `$' unexpected ...
user avatar
0 votes
1 answer
38 views

tar command in for loop starts from the wrong number

backup/ has the following files. ubuntu@ip-172-31-8-46:~/$ ls backup/ itrpl_dsm_10_1.tif itrpl_dsm_12_3.tif itrpl_dsm_2_3.tif itrpl_dsm_4_3.tif itrpl_dsm_6_3.tif itrpl_dsm_8_3.tif itrpl_dsm_10_2....
user avatar
  • 165
-1 votes
1 answer
34 views

bash command variable creation

I have this command that I've created and would like to place it in a variable. sort -k 1,1 | tr " " "\n" | users | wc -l Such as the one below, however, as of now the output produces an error and ...
user avatar
  • 1
0 votes
1 answer
281 views

Pass Array Variable to MATLAB Function in Bash

Aim I am using multiple text files to set variables and array variables. These are the input arguments to a MATLAB function, that iteratively creates url download strings based on these variables, ...
user avatar
  • 3
0 votes
2 answers
90 views

How to expand variable within a single-quoted argument?

I am trying to perform the following without luck: SORT_BY='-k3,3r -k2,2 -k1,1r' awk 'NR<4{print $0;next}{print $0 | sort '"${SORT_BY}"' -t"~"}' I have tried with all sorts of quotes, unquote, ...
user avatar
-1 votes
1 answer
349 views

Wildcard variables in xargs for parallel processing

Issue I have an issue using an input variable VAR in a function (i.e. ls) with the wilcard *, when this funciton is within an xargs bash call. This xargs function repeats over each member of a list ...
user avatar
  • 3

1
2 3 4 5 6