I am trying to increment a counter variable that sits within a seperate text variable. I am initializing the counter variable once only at the start of my code. I expected to be able to increment the counter and have the text variable (that countains the counter) display as incremented throughout my code, only this isn't the case.
For example, using a text file containing the word "hello" as it
s contents. I expected the code below to give me 2 seperate text files like so:
The issue is, I'm receiving:
I am aware that I can simply initialize the variable..
later on, after incrementing "run_number" but this seems redundant.
Any help is appreciated.
F
Last edited by Scrutinizer; 03-20-2017 at 02:07 AM..
Reason: Additional code tags
What you call "sitting within" is never the case.
After the assignment:
The variable run simply contains the string testing1
There is no variable contained in another variable..
This User Gave Thanks to Scrutinizer For This Post:
I see. Do you know if there is a way to increment a variable within a variable and have it remain throughout? I don't want it to be a one time thing because I plan on incrementing it in a for loop over several iterations.
Not really, no. In Bash, variables are only ever updated at the time something is assigned to them. If other variables that were used to determine their value are themselves updated, this will not change the values of other variables dynamically.
A quick example is probably the easiest way to demonstrate this.
Here's what you'll see when you run this.
So basically, the contents of a variable will only ever be updated when something is assigned to that variable, regardless of what happens to any other variables that were originally used to determine the contents of the variable in question.
I see. Do you know if there is a way to increment a variable within a variable and have it remain throughout? I don't want it to be a one time thing because I plan on incrementing it in a for loop over several iterations.
I think you really have to rebuild the run variable every time you increment the integer variable.
Examples:
Andrew
Hi All,
I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Hi,
I need to update rows in a table based on the values in an array variable.
code is :
while read line
do
error_msg="$(echo $line)"
index=`expr $index+1`
done <"logs/$ffile"
rows_count=${#error_msg
}
i=0
while
do
echo "error msgs is... (2 Replies)
Hi all,
Hereby wish to have your advise for below:
Main concept is
I intend to get current directory of my script file.
This script file will be copied to /etc/init.d.
A string in this copy will be replaced with current directory value.
Below is original script file:
... (6 Replies)
Hi,
I have been attempting to install source code from xcrysden with little to no luck. I have attempted to follow the instructions given on the site but made the mistake on the code I downloaded. This was pointed out to my by the developer and I have since downloaded the proper code. However... (4 Replies)
I have another question I am stuck at :wall:
I have a text file with two columns, like so...
2 0.0627279
3 0.0794451
4 0.108705
5 0.137739
6 0.190394
7 0.217407
8 0.241764
9 0.344458
10 0.460762
I'd like to go through the file line by line until the value in the second column... (3 Replies)
can anyone please help me with this:
i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure...
... (4 Replies)
Dear all,
I have basic knowledge of Unix script and her I am trying to process variable length and variable format CSV file.
The file length will depend on the numbers of Earnings/Deductions/Direct Deposits.
And
The format will depend on whether it is Earnings/Deductions or Direct Deposits... (2 Replies)
Hi all,
I have a variable say var1 (output from somewhere, which I can't change)which store something like this:
echo $var1
name=fred
age=25
address="123 abc"
password=pass1234
how can I make the variable $name, $age, $address and $password contain the info?
I mean do this in a... (1 Reply)
I want to instert Category:XXXXX into the 2. line
something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong:
sed "2i\\${n}Category:$cat\n"
Sample:
Titel Blahh Blahh abllk sdhsd sjdhf
Blahh Blah Blahh
Blahh
Should look like... (2 Replies)
Hello all,
I am very new at both AutoSys and VBScript. I have looked at the manual for hours however I just can't figure it out, the following is the problem:
NOTE: AutoSys is being used in all Windows environment. But realizing that this is a UNIX forum, please do provide the answer however... (1 Reply)