I have a script which sets some variable, now I know to set them for a session I should source it. But my problem is I am using some relative path in the script, so if I source the script those path don't work. How to solve this. Please see my example script:
#!/bin/bash
BASEDIR=$(dirname "$0")
source $BASEDIR/../.text_formatter #Invoke the formatter bash script
export var1 = 1
I have added the path of the script in PATH, so that I can run this script as a program. But if I source the script I get error no such file or directory: ./../.text_formatter. If I dont source it, obviously the var1 value does not persist. How to solve this issue ? I would like to avoid source, so that user can directly run this as a program, but would like to know if solution exists with source also.