#!/usr/bin/env bash
scriptdir="$HOME"
touch $scriptdir/foo.txt
. "$scriptdir/foo.txt" ||
{ echo "Missing '$scriptdir/foo.txt'. Exiting." ;
exit 1 ;}
echo "$scriptdir/foo.txt is present"
echo
rm "$scriptdir/foo.txt"
. "$scriptdir/foo.txt" ||
{ echo "Missing '$scriptdir/foo.txt'. Exiting." ;
exit 1 ;}
I don't understand the use of . in . "$scriptdir/foo.txt" ||
It seems to be functioning similar to if [ -f "$scriptdir/foo.txt ] , yes?
Such that
scriptdir="$HOME"
touch $scriptdir/foo.txt
if [ -f "$scriptdir/foo.txt" ] ; then
echo
else
{ echo "Missing '$scriptdir/foo.txt'. Exiting." ;
exit 1 ;}
fi
yields a similar result.
Can someone elaborate on the use of . here?
If I write a script in foo.txt then that script will presumably run because . causes a file to execute rather than just looking to see if it is there? And, as long as $scriptdir/foo.txt is present and executable, then the right half of || will never run because the left half is returning an exit status of zero?