I use a lot of external files in my scripts.But I have a problem, that if I source a file with exit in the contents of the file, the script exits from loading and the strings that I want to use are gone.Example main.sh:#!/bin/bashclear;source /opt/external-svn/config.sh;echo $var1 and $var2 and $var3;Example config.sh:#!/bin/bashvar1=foo bar is greatvar2=foooo baar is greatervar3=foooooooo baaaaaar is \to longexit 0Problem is the multiline var3,so I want to use sourcefor var1 and var2. The following is possible but not nice:var1=$(cat /opt/external-svn/config.sh |awk -F'' '/^var1/ {print $2}');This is only work for single line not for var3.Is there a simple / easy solution ?update because I'm to stupid to make a correct answer@Gillesno not working the file in raw is here for suggestions raw.githubusercontent.com/gorgone/temptest/master/config.sh#!/bin/bashFILE=/tmp/$(basename $0).$$.tmpconfigsh=/opt/external-svn/config.shgrep -vE '^exit' $configsh > $TFILEsource $TFILEexit the mainscript and got echo to screen @Anthon it's also not working for the my file on github Update2 found solutioni found the magic ONE i use the idea but its not a generic solutiononly for my special casecat config.sh |sed 's/if [ $# = 0 ]/if [ $# = 1 ]/g' >config.sourceso i can source the file but the best way is to have a generic solution for all files
bash source script.sh with exit 0
bash;shell script;awk;source
If you have abc.inc:x=1exit 0and klm.inc:y=2exit 0then if you have combine script:#!/bin/bashfor fn in abc klm; do  grep -vE '^exit' $fn.inc > /tmp/xyz.tmp  source /tmp/xyz.tmpdoneecho x: $xecho y: $yyou can run combine and get as output:x: 1y: 2This assumes that your exit statement are at the beginning of their lines, you might have to adjust the grep if they are not