BefittingTheorem
BefittingTheorem

Reputation: 10629

Directory of running script in Fish shell

I'm trying to get SBT running using the Fish shell. Below is the equivalent Bash script of what I'm trying to achieve:

java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"

I see in the Fish documentation that $@ in Bash can be replaced with $argv in Fish. But I cannot see what to replace dirname $0 with.

Does anyone know the equivalent script in Fish?

Upvotes: 5

Views: 1491

Answers (3)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84343

Use status Builtin and argv Variable

The fish shell uses the status command to return information about a number of things, including the filename or directory of the currently-running script. It also uses the argv variable rather than Bash's $@. Additionally, fish's variables are lists, so you don't want to quote them the way you do in Bash unless you're trying to treat all the contents of the list as a single string.

Assuming you're running this from a file such as foo.fish, the way to do this would be to include the following line in your script file:

java -Xmx512M -jar (status dirname)/sbt-launch.jar $argv

Upvotes: 0

otherchirps
otherchirps

Reputation: 1846

$_ only seems to work directly via the reader/command line, or when the script is sourced, for me.

Maybe this will work for you:

java -Xmx512M -jar (dirname (status -f))/sbt-launch.jar "$argv"      # fish

Upvotes: 5

Dennis Williamson
Dennis Williamson

Reputation: 360055

The fish equivalent to this:

java -Xmx512M -jar $(dirname $0)/sbt-launch.jar "$@"     # Bash, et al

is

java -Xmx512M -jar (dirname $_)/sbt-launch.jar "$argv"      # fish

Upvotes: 1

Related Questions