All Questions
Tagged with variable-substitution scripting
10 questions
-3
votes
2
answers
1k
views
defining variables inside function
After some reading somewhere on this interwebs, I found that it was best practice to to the following when using the output of a command as a variable:
FILE_CORE_NAME="$(/usr/bin/env basename $(/...
2
votes
2
answers
2k
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&/...
0
votes
1
answer
88
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....
2
votes
1
answer
12k
views
using variables inside the curl command not working in bash script
I am trying to write a bash script to update certain nodes in my repository. I wrote below script, but it does not seem to be working when I use variables inside curl. Below is the code. I tried all ...
0
votes
1
answer
820
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"
...
1
vote
2
answers
707
views
Substrings in shell script
Am trying to get a substring from a string but am getting the error: ${curr_rec:3:4}: bad substitution
#!/bin/ksh
get_file_totals()
{
if [ -e "$file_name" ]
then
IFS=''
...
-2
votes
1
answer
3k
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 the ...
11
votes
1
answer
69k
views
How to reassign new values to array elements?
I'm trying to figure out like three or four things at the same time.The most I need help with is how to get the greatest number in all the files that I have created on a prior run of my script, that ...
0
votes
1
answer
987
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 {
...
5
votes
1
answer
15k
views
when to use double quotes with a variable in shell script? [duplicate]
I am in a confusion with what is meant by the double quotes referring to a variable. For example following two scripts gives the same output. What is really meant by the double quotes?
Script1
...