I have a script "task.sh" with the following content:
#!/bin/bash
CUR_DIR=`pwd`
SCRIPTPATH="${CUR_DIR}/`dirname $0`"
when I call it with "bash task.sh" it works as expected but when it is called with ". task.sh"
$ . log/task.sh
dirname: invalid option -- b
Try `dirname --help' for more information.
When the script is being scheduled in crontab it is not working as well. Can someone tell me what am I doing wrong or a different way in order to get the directory of a script that is not the current directory ?
SCRIPTPATH="${CUR_DIR}/`dirname "$0"`"
, i.e. quote$0
. Besides that,CUR_DIR
seems to be redundant here. – Brachiate