0

I am new to Bash Scripting and would need help to make a simple script that I will run on my CentOS. I would like the script to check if classpath is empty like this:

> [root@hdp ~]# echo $CLASSPATH
> 
> [root@hdp ~]#

do: export CLASSPATH="something"

else

echo -n "There's already a classpath! Appending!"

If there already is a classpath set, append to the existing one without overwriting to it.

10
  • 1
    if [[ $CLASSPATH ]]; then echo nice; else echo empty; fi ? Commented Jan 1, 2018 at 23:24
  • @PesaThe awesome, how do I append but not overwrite? Commented Jan 1, 2018 at 23:43
  • I don't know what you mean. Your question is unclear. Update it, include desired output etc. See How to create a Minimal, Complete, and Verifiable example. Commented Jan 1, 2018 at 23:52
  • @PesaThe I don't know how I could be more clear. Either the classpath is empty or it is set, the example you provide checks that. Imagine if there already is a set classpath, the if statement will then reach "nice". The next step would be to add something to the classpath without overwriting what's already there (since it is set containing jars etc). Commented Jan 2, 2018 at 0:00
  • Oh sorry, I didn't see the end of the question. Combine the if I posted and Cyrus' answer to do what you need :) Commented Jan 2, 2018 at 0:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.