5
On Linux-based systems whenever I need to use the following command:
#!/bin/bash
BASEDIR=$(dirname "$0")
echo $BASEDIR
But I read in different places that $(dirname "$0")
not supported by Mac OS X and BSD-based systems (apparently both based on Unix).
I saw some alternatives, but all always have a criticism, or some mention saying that fails in something.
What I need is to know if there is any way to get the current script directory cross-platfom (Unix-like)?
Another thing, I would like to know how to get both the actual directory path and the path of a symbolic link.
Note: Doesn’t have to be with
bash
Ah, okay, kkkkk, I wavered in the answer
– Wallace Maxters
the
pwd
does not suit your case? http://devblog.drall.com.br/get/– Pablo Tondolo de Vargas
@Pablovargas thank you, you will tell me if this is cross? However as soon as I install BSD and linux I will test it too. Thank you for now.
– Guilherme Nascimento
I can’t tell you, I’ve always used these commands only on Linux
– Pablo Tondolo de Vargas
pwd
is POSIX standard, which means it is highly compatible not only on UNIX-based operating systems (Linux, Android, iOS, Openbsd, macOS, HP-UX, Solaris, ...) but also on Windows 10 through Bash or earlier versions installing SUA(official MS)/Cygwin– rodorgas