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

Time:09-21

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.

CodePudding user response:

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
}

CodePudding user response:

It look's like a fork. Try out

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

CodePudding user response:

Another option would be to define an alias, eg:

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