Why am I getting this error, I am trying to source this set.confuser@connect:~/testenv$ source $(cd $(dirname $0) && pwd)/set.confdirname: invalid option -- 'b'Try 'dirname --help' for more information.-bash: /home/tempuser/set.conf: No such file or directoryI tried adding -- $0 on command prompt it works well but. How can I run this in script?
dirname invalid option `b`
bash
$0 inside a script is the script's name.At the prompt, it's the shell's name, which is probably -bash in your case.dirname is treating the leading dash as introducing a command line option, -b, which it doesn't support.The code you're using won't work at the prompt.  You could paste it inside a file and run the file instead.Try dirname -- $0 instead: most commands let you write -- to make it treat everything that follows as parameters instead of options.  In this case, it won't fix the problem, but it should make it clearer what the problem is.