Your script and specially its inner cd
commands works just fine when called from bash
with using either the source
or the equivalent .
commands.
The main issue is, as already stated in @adonis comment, your shell, after properly changing its directory, will exit unless a file precisely named "*.cfg" does exist, which is very doubtful.
As I guess you want to use *.cfg as a pattern, here is how I would slightly modify your script for it to work as expected:
#!/bin/bash # Note that the shebang is useless for a sourced script
model_dir=/mypath
chdir() { # use either function or (), both is a non portable syntax
cd $1
}
chdir ${model_dir}/config
if [ ! -s *.cfg ]; then # Single brackets here for the shell to expand *.cfg
echo $(date) "configure file does not exist"
exit 1 # dubious in a sourced script, it will end the main and only shell interpreter
fi