The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [variable-substitution]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
2answers
1k views

Passing an argument with double and single quotes to another call in bash [closed]

I have a call ./run.sh name --vars="service_name='someothername'" and I'm trying to call another program with exactly same --vars="service_name='someothername'" argument from run.sh, however when ...
0
votes
1answer
65 views

Why is variable substitution called variable substitution if we retrieve the value?

I've read here the following text: The name of a variable is a placeholder for its value, the data it holds. Referencing (retrieving) its value is called variable substitution. If we retrieve/...
0
votes
1answer
476 views

Redirect the output of a command with variables to an array

I am trying to redirect the output of a command that contains couple of user input variables to an array. I first tried this script - echo "Type the ACL name" read acl echo "Type the DATACENTER name" ...
0
votes
1answer
143 views

Bash add text on line script [closed]

Trying to get my script to work but it won't work. Here is my script #!/bin/bash a="* * * * * /home/server/scripts/check.sh" b="0 06,18 * * * /home/server/scripts/checks2.sh" sudo sed -i '28s/^/'$b'\...
0
votes
2answers
736 views

/usr/bin/find invocation doesn't work when used with command substitution [duplicate]

In a script, I have: CMD='/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; ' MD5=$("${CMD}") But the script gives the error: -bash: /usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; : ...
0
votes
2answers
132 views

Find the position of repeated character “&”

How can determine the position of “&” in the column number 5 to substring the value 2 or substring value 3 by awk functions column1|column2|column3|column4|variable1:value1 & variable2:...
0
votes
1answer
1k views

Searching path as search pattern in grep command

I have saved the path in the variable . var="/home/myfolder/subfolder" Need to search whether the path in available in a text file using grep. grep -l '${var}' * >abc.txt I'm trying to list ...
0
votes
1answer
538 views

Jquery like templates for formatting strings in bash

#!/bin/bash rm all for f in assets/css/*.css; do printf "<style type='text/css' >\n" >> all cat $f >> all printf "</style>\n <!-----$f---->" >> all echo "$f ...
0
votes
1answer
46 views

Inserting variables in a file path on GNU linux (SLES 11)

I am tryin to insert 3 variables to build a path, but unable to get it . I am trying the below log_path="/vol02/logs/$dname/logs/103602_$msname/${msname}_start.log" dname=cfp msname=cfp003 i get ...
0
votes
2answers
1k views

Expect Scripts - Reading from Files and Accepting User Input

How can I write an "Expect" script to: iterate over a list of IP addresses and log in to each to perform commands (like in a BASH for loop). Right now I just copy/pasted the few lines that are my ...
0
votes
1answer
113 views

Special Parameter query - multiple used to obtain command name? [duplicate]

In a uni text provided us to cover bash scripting, the following variable assignment has got be stumped and I've yet to get an answer back from anyone, hence hopefully someone on here can help. name=$...
0
votes
1answer
864 views

Why does a working standalone nested function/script not work inside a larger script? [duplicate]

The following (nested) function/s function hpf_matrix { # Positional Parameters Matrix_Dimension="${1}" Center_Cell_Value="${2}" # Define the cell value(s) function hpf_cell_value { ...
0
votes
1answer
150 views

Colon breaks the variable subsitution [closed]

I am trying to lookup some C functions so that I could debug while using strace. So I setup a bash function to look it up in firefox (or links), but the substitution falls apart with : and escaping ...
0
votes
1answer
2k views

Unable to loop through cURL command

I am able to execute individual cURL commands using, curl -u user:password -v -XPOST -H 'Content-type: text/xml' -d '<featureType><name>quadrella_indica</name></featureType>' ...
0
votes
0answers
45 views

Why can't execute ls or cp commands with a variable as an argument [duplicate]

I am debugging a bash script. It executes cp and mv commands in the script when a variable containing a path is used as the argument to the command. I have duplicated it in the terminal as follows: ...
0
votes
0answers
158 views

Use variable inside sed command [duplicate]

how can i use variables inside this sed command? sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile inside -e '{w $DIR/tempfile' -e 'd;}' the $DIR/tempfile isn't recognized
0
votes
2answers
84 views

How can I export a variable in bash where the variable name is comprised of two variables?

I'm trying to export variables inside of a for loop where I wanted each iteration of the loop to change what variable was being written to. I've been looking for the right syntax to satisfy exporting ...
0
votes
0answers
14 views

Interaction of sed and for loop [duplicate]

for i in {1..25}; do cat file$((i)) | sed 's/.*/$((i))/'; done doesn't print the current value of i but just $((i)). How can I make it print the value of i instead?
0
votes
2answers
118 views

for loop variable assignment with whitespaces

Im collecting the LPAR names and assigning to a variable on AIX , Then using multiple commands for processing. LPAR Names on the system are : ABCD56777 TSM Mobile CD CPT 2 for lparname in `...
0
votes
0answers
41 views

Variable expansion succeeds with echo but fails without a command (execution by expansion) [duplicate]

I created a file nano ~/uncwe/configurations/variables.sh. This file contains: set -a rse="~/${repo}/internal_software/rse.sh" set +a I sourced the file, then tried to execute: ${rse} bash ${rse} ...
0
votes
3answers
366 views

Test nested variables in a while loop

I was trying to insert a nested variable as a while loop condition but I can't manage to expand it properly. print_message() { timer=0 timer_condition="$2" while [[ $timer_condition ]]; ...
0
votes
1answer
1k views

Bash variable substitution with spaces [duplicate]

There's next code: TITLE="Some value with spaces" DIALOG="${DIALOG=dialog} --clear --no-tags --tab-correct --backtitle $TITLE " ... $DIALOG --title "Some title --menu "Menu" 15 60 5 "1" "menu1" "2" "...
0
votes
0answers
100 views

How to resolve a variable's value inside an array in bash

I have a few files whose names I have assigned into variables. (There may be n number of files). Those variables are passed into an array. Now I want to print the names of the original files using ...
0
votes
1answer
581 views

Copy selected files had subtitutions in name

I have some folders: oldA with A_1.aaa, A_2.aaa, A_1.bbb, A.def, A.ghi oldB with B_1.aaa, B_2.aaa, B_1.bbb, B.def, B.ghi and so on and need to copy them to another folder with selection. I want ...
0
votes
2answers
1k views

How do I assign last month's date (year and month only - 2016-07) as a variable? [duplicate]

I am having trouble with using date as a variable in a bash script. I will admit that I have zero experience writing anything – in bash or otherwise – but I’ve been tasked with figuring this out. I ...
-1
votes
1answer
1k views

Variable won't get expanded when INSIDE mysql shell

Before creating a new mysql user and DB, I did: read sps -s # Inputing and saving the sps (password) value. echo ${sps} # sps password value echoed. mysql -u root -p[PASSWORD] mysql>...
-1
votes
2answers
67 views

Variable substitution from/to file [duplicate]

How do I replace placeholders in a file with variables from another file? (Like docker-compose is doing it.) I found many articles about single variable replacements or replacement by environment ...
-1
votes
1answer
56 views

how generate and substitute files with sed [closed]

I need to change the seed's value, the output (HA.xyz) and the namefile to generate 100 different files. # MSA: H2O seed 129472 tolerance 1.0 filetype xyz output HA.xyz Structure H2O.xyz number ...
-2
votes
2answers
99 views

How to execute a command that has many nested single and double quotes with a quoted variable in bash

Here is my simple script #!/bin/sh thefile=/home/ark/arkserver/ShooterGame/Saved/SaveIsland/1288804998.arktribe while inotifywait "${thefile}" ; do a=\"`strings ${thefile} | tail -n 5 | head -n ...
-2
votes
1answer
133 views

how do I make a $VAR empty so it don't effect the command line argument and still be within that argument?

This is the basic setting for hsetroot for it to work: hsetroot -center /path/to/image/ - setting the wallpaper with just that the picture. To use these options, just one has to be place within the ...
-2
votes
1answer
1k views

why does the dollar sign cause this command to be executed?

test_script.sh: #!/bin/sh D1="$(dirname $0)" echo $D1 D0="(dirname $0)" echo $D0 What I type on the command line: $ ./test_script.sh Output: . (dirname ./test_script.sh) What significance does ...