In bash you can use $0
variable to get the location of the current script. How I do the same in Nu? echo $nu
doesn't seem to have anything I can use.
Asked
Active
Viewed 713 times
5

Jacob Wang
- 4,411
- 5
- 29
- 43
-
Try echo(script) or echo $pwd ls – asha Jan 13 '23 at 21:10
3 Answers
4
As long as you know the name of the file, you can do:
$env.FILE_PWD | path join filename
This will only work if you are executing the file as a script, not sourcing it.

dols3m
- 1,676
- 2
- 16
- 25
-
My usecase is really to find the location of the script so FILE_PWD is exactly what I'm looking for. Thank you! – Jacob Wang Jan 16 '23 at 12:07
-
It's possible this value might change so worth following https://github.com/nushell/nushell/issues/7692 – Jacob Wang Jan 16 '23 at 12:08
0
I don't think there's a way to do this yet. I was playing with history | last
but it's one off, as you'd expect.

Darren
- 483
- 7
- 15
-1
($nu.config-path | path dirname )

jiahut
- 1,451
- 15
- 14
-
While this works for getting the path to the config file, it doesn't work in general for any given script regardless of its location. – Jonathan E. Landrum Aug 16 '22 at 18:12