0

I'm new to Linux but i'm doing a tutorial for Antlr4. Recently, I've come into a problem. When I try to set up my Antlr4 project, I run the following commands in a terminal:

antlr4 MyGram.g4
javac *.java
grun MyGram prog test.in
dot -Tpdf test.dot > test.pdf

Everything runs fine and it creates a pdf file showing the parse tree. However, when I put these commands into a bash script called build.sh:

#!/bin/bash

antlr4 MyGram.g4
javac *.java
grun MyGram prog test.in
dot -Tpdf test.dot > test.pdf

and then run the command: ./build.sh and I get the following errors and no pdf file is created:

./build.sh: line 3: antlr4: command not found
javac: file not found: *.java
Usage: javac <options> <source files>
use -help for a list of possible options
./build.sh: line 5: grun: command not found
Error: dot: can't open test.dot

Can anyone please explain the reason why I'm getting these errors ? I'm running Ubuntu 18.04 on VMware Workstation 14 Player.

2

2 Answers 2

1

For some reason, antlr4 and grun are not in your $PATH.

type antlr4 

will show you where it it. Add that to your PATH in your .bashrc or .profile

Sign up to request clarification or add additional context in comments.

Comments

1

antlr4 and grun are aliases that you have defined in your command window.

When you run your script, you are in a different environment.

So you should either:

  1. define your aliases at the beginning of your script
  2. not use aliases in your script

I agree with @Tejas comment: you should use full paths in your script (far easier to maintain)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.