Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Censoring Words - Looping Until the Value Passes

Paul Sharpe
Paul Sharpe
2,027 Points

Why cant I copy into the console? Im getting pretty tired of typing out clear && javac TreeStory.java && java TreeStory!

Why cant I copy into the console? Im getting pretty tired of typing out clear && javac TreeStory.java && java TreeStory every time I return to my work space. Im lazy!

2 Answers

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

You can do this.

If you feel writing the same command over and over again in Bash, which is Console environment where you write clear && javac TreeStory.java && java TreeStory, you have two options:

  • create script run.sh and save it in workspaces

In order to do that create file run.sh (it can have any name actually and not sh neccessarily), and put into it the line, that you execute:

clear && javac TreeStory.java && java TreeStory

The type in console

chmod +x run.sh

After that you can type the following

./run.sh

And your script will execute commands in script

Try that out and let me know i that worked

Second option will be to create alias. But this one you will have to re-create every time you run workspaces...

If you want to know more about aliasing and console commands, take a nice course here at Treehouse

https://teamtreehouse.com/library/console-foundations

hey, i tried it and it worked. thank you.

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

Great:)

Make sure you also use auto-completion.

When you start typing anything, like javac Tree, try to hit "Tab" button, it should auto-complete Tree to TreeStory.java. In this case Bash is configured to look for file in the current directory.

The same works for commands. If you type java and hit Tab twice, console will show you possible programs that Bash knows, and that are installed. Try that out as well.

Also if you are interested, here is how alias works

Type in console

alias rj="clear && javac TreeStory.java && java TreeStory"

Then you can type rj in console, and that will execute the same command, but without this ./

There are benefits for using both approaches. Of course with Java it is better to learn IDE :) with 'Local Development Environments Course', because it does all the hard work for you, but still knowing Bash commands can be very helpful.

http://www.tldp.org/LDP/abs/html/aliases.html

https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions

Paul Sharpe
Paul Sharpe
2,027 Points

I have actually completed that course and will be going onto a workshop, but I will certainly do this when I start the next stage of java and report back if it works, Thank you very much!