0

I've checked this answer first:

My question still is:

If I put these lines to my ~.zshrc file :

JAVA_HOME="/user/lib/jvm/java-7-openjdk-amd64"
export JAVA_HOME

alias sudo="sudo env JAVA_HOME=$JAVA_HOME"

Then do logout.

Then try :

> sudo ./somejava-stuff.sh

I still see "The JAVA_HOME environment variable is not defined"

When I check whether my alias was applied:

> which sudo 

I got unexpected output that says:

"sudo: aliased to nocorrect sudo"

Q: Why it is so?

If I do this manually:

> sudo env JAVA_HOME=$JAVA_HOME ./somejava-stuff.sh

It works fine.

-- Also I tried to set "alias with the space" as was suggested here

I tired also this:

...

alias sudo='nocorrect sudo'
alias sudo="sudo env JAVA_HOME=$JAVA_HOME "

Like was suggested here.

Community
  • 1
  • 1
ses
  • 13,174
  • 31
  • 123
  • 226
  • Ok.. I guess this "just not working": https://github.com/sorin-ionescu/prezto/issues/531 – ses Apr 09 '14 at 22:13

1 Answers1

1

Q: Why it is so?

This is because your init files override your custom sudo alias. You can only have one alias for one command at a time.

What you can do:

Method 1

Choose another name for your alias:

alias jsudo='sudo env JAVA_HOME="$JAVA_HOME"'

Also note the difference in quoting between your version and this.

Method 2

Find and delete the line in your zsh init files that is overriding your alias. Somewhere, there will be a line saying alias sudo='nocorrect sudo'.

If you are unable to find this line, you have to stick with Method 1. This would be a failure on your part, and not a problem with zsh or Linux.

Update your sudo alias with

alias sudo='nocorrect sudo env JAVA_HOME="$JAVA_HOME"'

PS: The whole nocorrect business is to prevent zsh from correcting your command, which is typically not helpful for sudo.

that other guy
  • 116,971
  • 11
  • 170
  • 194