chrisdottel
chrisdottel

Reputation: 1133

Bash crashes when executing script that defines a function with the same as an existing command

I am very new to bash. All I want to do is run this nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java without having to remember the path at the end. I figured the instafix would be to just do this...

nvvp() {
    nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java
}

Then I could just call nvvp and it would boot up Nvidia's Visual Profiler. But this just crashes my terminal.

Upvotes: 2

Views: 323

Answers (3)

markp-fuso
markp-fuso

Reputation: 34074

Another option would be to define an alias, eg:

alias nvvp='nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java'

Upvotes: 0

Socowi
Socowi

Reputation: 27205

The redefinition of nvvp is global. Inside the function nvvp you execute that very same function, causing an infinite recursion. To call the actual binary instead of the function, use bash's command built-in:

nvvp() {
    command nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java
}

Upvotes: 4

John Goofy
John Goofy

Reputation: 1419

It look's like a fork. Try out

another_name() {
nvvp -vm /usr/lib64/jvm/jre-1.8.0/bin/java
}

Upvotes: 3

Related Questions