Bash script is making me zany!
Below is the script as I have it now, I am still working on building it so it's not complete. Anyhow there is one area that is not working no matter how I try to get it to... and it's driving me crazy!
The setup/function... I have a text file called... txtBuild.txt that contains the last build number of a project I am working on. Currently I have to manually tar the existing instance of the application, then manually copy over the new build so I can start using the new build. I am writing this script to use the last build number ( formatted this way YYYYMMDD-### ) for the tarball of the last build. Then the new build number is created ( that part works fabulously! ) and written into txtBuild.txt. But it isn't. And this is the problem I have been trying to sort out! The script... Code:
#!/bin/bash |
Quote:
Code:
echo "the build number is [[$build]]" |
I agree that due to several syntax errors YY is not being assigned a value.
bash does not allow spaces before or after a variable assignment. You need to use command substitution as posted above to assign the output of the date command to your variable. Code:
i=$(($newline+1)) # increment value by 1 Again as posted your confusing the output of the date command and that echo $build is actually only a line feed. You can check for syntax errors at https://www.shellcheck.net/ |
Well, thank you gentlemen! Much appreciation on the lesson and help! I am still learning the nuances of BASH. While I have been using Linux since 1999... I never got into scripting much. Now... I am finally finding a use for it so I am learning!
|
While a healthy project, I am curious why you don't just place the latest build number in the file name and then do your operations on it to extract and make the next build number? (just a thought)
|
And it's not good to write to a file you are currently reading from.
Because it has got only one line, instead of a while loop use a one-time Code:
read -r line < $file |
All times are GMT -5. The time now is 03:37 PM. |