I have just compiled the source code for a program called JohnTheRipper. Currently, if I want to run john I have to cd into the run/ directory and execute it with ./john. However, I would much prefer being able to run the john command from any directory, as if it were installed system wide. I can't make an alias for this, because I need to be able to pass parameters to the binary. So I tried making a small shell script.


/home/username/tools/JohnTheRipper/run/john $@

I placed this script into /usr/local/bin so that it is in my path. This script works, but ONLY if I run it by specifying the path.

$ ls john -la
-rwxr-xr-x 1 root root 56 Mar 20 03:54 john
$ ./john --test
Will run 4 OpenMP threads
Benchmarking: descrypt, traditional crypt(3) [DES 256/256 AVX2-16]... (4xOMP)

It will not work if I try running it by using the $PATH environment variable

$ which john
$ john --test
bash: syntax error near unexpected token `--test'

Why is this the case? Why aren't the command line arguments being passed to my shell script? And how can I set it up so that I can run the john command from any directory, allowing me to pass it arguments?

Note The solution must be able to accept relative paths when passing parameters to john. For example, if I am in the directory d/ with a file wordlist.txt I want to be able to run john as such:

john --wordlist=./wordlist.txt
  • 3
    (1) What is the output of type -a john? (2) You should quote $@ like this: "$@". (3) alias john='/home/username/tools/JohnTheRipper/run/john' shouldn't interfere with arguments that follow john while invoking. – Kamil Maciorowski Mar 20 '19 at 9:26
  • A better plan would be to symlink something in PATH to the path to john. – jeremysprofile Mar 20 '19 at 16:55

The comment by Kamil Maciorowski helped me solve this issue. It was user error.

$ type -a john
john is aliased to `(cd ~/tools/JohnTheRipper/run/ && ./john )'
john is /usr/local/bin/john

In the above you can see the output of type -a. I originally created an alias that used a subscript, and when that didn't work I tried to symlink the executable, I tried different aliases, and I tried creating the aforementioned script. However, none of these worked because every time I made a change to .bashrc I ran

$ source .bashrc

I was unaware that source would not overwrite my original john alias... Since aliases take precedence over the $PATH variable, this whole time john was executing the same original subshell that wouldn't take arguments. By running unalias john, now everything works.

NOTE When it comes to making a symlink in /usr/local/bin, I agree this would be a better alternative, but unfortunately it does not work in this situation, as you can see from the following output:

$ ls -la john
lrwxrwxrwx 1 root root 39 Mar 20 12:31 john -> /home/username/tools/JohnTheRipper/run/john
$ john --test
fopen: $JOHN/john.conf: No such file or directory
  • You still have an error: $@ should be "$@". Without the quotes, you cannot pass in quoted or escaped arguments. – tripleee Mar 22 '19 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.