Pergunta

Em um script shell peixes, é possível obter o caminho onde vive o shell script? Em bash, você pode usar a variável BASH_SOURCE para fazer isso.

Foi útil?

Solução

One way is to use the status command.

eg.

~/tmp> echo status -f > show_filename.fish
~/tmp> fish show_filename.fish
/home/foo/tmp/show_filename.fish

--

Ah, sorry - judging by your comment, I misread the question. I thought you meant the fully qualified path, instead of the script's directory.

You could just send the status result to dirname. It's not a built-in function of fish, like status is, but fish tends to outsource as much of this functionality as it can anyway (see "The law of minimalism", over in the fish design doc). I can't see anything better commands in the docs for this, so maybe this is as good as we can get for now?

Amending the example, change the contents of show_filename.fish to be:

dirname (status -f)

Now you should get:

~/tmp> fish show_filename.fish
/home/foo/tmp
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top