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.

HumbleMan
  • 53
  • 7
  • 1
    `if [[ $CLASSPATH ]]; then echo nice; else echo empty; fi` ? – PesaThe Jan 01 '18 at 23:24
  • @PesaThe awesome, how do I append but not overwrite? – HumbleMan Jan 01 '18 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](https://stackoverflow.com/help/mcve). – PesaThe Jan 01 '18 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). – HumbleMan Jan 02 '18 at 00:00
  • Oh sorry, I didn't see the end of the question. Combine the `if` I posted and [Cyrus' answer](https://stackoverflow.com/a/48054256/6176817) to do what you need :) – PesaThe Jan 02 '18 at 00:02
  • @PesaThe The answer by you and Cyrus answered all my questions. I could upvote and accept your solution if you post it. And thanks, btw! – HumbleMan Jan 02 '18 at 00:03
  • @Cyrus did you got offended in some way? This is far from a duplicate if you take a look at the question you are refering to. And why did you remove your answer? It was useful for me and would be useful to others as well. – HumbleMan Jan 02 '18 at 00:12
  • I deleted my answer because three out of four answers on [this](https://stackoverflow.com/a/580886/3776858) page are largely identical to mine. – Cyrus Jan 02 '18 at 00:17
  • So? Still not a duplicate. Not even close. – HumbleMan Jan 02 '18 at 00:19
  • Also see [What is a classpath?](https://stackoverflow.com/q/2396493/608639). It discusses various ways to add a path to classpath, including starting the VM with `-classpath`. – jww Jan 02 '18 at 03:11

0 Answers0