I have following code:
VAR1=""
ANOTHER_VAR="$VAR1/path/to/file"
ANOTHER_VAR_2="$VAR1/path/to/another/file"
...
# getopts which reads params from command line and sets the VAR1
The problem is that setting the VAR1 after ANOTHER_VARs are set makes their paths without the VAR1 part. I can't move the getopts above those because the script is long and there are many methods which depends on the variables and on other methods. Any ideas how to solve this?
ANOTHER_VARandANOTHER_VAR_2below thegetoptsinstead?count-stuff -d dir [-f|-a]that counts in file (-f) or another file (-a). Then you could have in your getopts loopd) VAR1=$optarg ;; f) function_that_uses_var1but I would suggest not doing that, and instead doingd) VAR1=$optarg ;; f) file_to_read=file ;; a) file_to_read=another_fileusing getopts strictly to acquire information about what was entered on the command line but not to do any work.