0

I would like to know if my following implementation is correct or wrong.

I have a variable called $MY_HUGE_PATH_VARIABLE.

I need to enhance it by adding a few directories and all directories within those directories.

I set it up like this:

export MY_HUGE_PATH_VARIABLE=$PATH_1/version1/*\:\
$PATH_2/version4/*\:\
$PATH_n/versionn/*\

Is this correct. Does that * work when exporting paths? Are there any other issues with this piece of script. I am working on a Redhat Linux machine and my script in bash shell.

My aim is to include all the jar files within these folders for my Java compilation. My intention is to understand this stuff. the shell has not really thrown any errors to me as of yet and the script is part of a bigger set-up which I have not yet tested.

3
  • What you are trying to do can be dangerous. Maybe checkout unix.stackexchange.com/questions/17715/… Commented Jun 8, 2016 at 9:32
  • I have .jar files within these paths, which i need to use for my Java code compilation. Thats why i am working on this sort of set-up Commented Jun 8, 2016 at 10:05
  • 2
    Ahh, this is somewhat of an XY Problem. Update your question and explain WHY you want to do this. You can write a bash script to run your jar, and list all dependencies individually, or you can do something like java -cp lib\*.jar;. myproject.MainClass which seems to be what you Commented Jun 8, 2016 at 10:18

2 Answers 2

3

EDIT:- you dont need to specify * here, in linux it works like this:-

export MY_HUGE_PATH_VARIABLE=$MY_HUGE_PATH_VARIABLE$( find $PATH_1/version1/ $PATH_2/version4/ $PATH_n/versionn/ -type d -printf ":%p" )
Sign up to request clarification or add additional context in comments.

3 Comments

Bash does not scan subdirectories of PATH variable recursively
I would be happy if you could give a small explanation of what happens as well. I am quite new to bash scripting
here find will search for -type d(directories) and printf will print "%p"(files) along with : from the space separated paths you provided in find command.
0

Please try the following:

export MY_HUGE_PATH_VARIABLE=$(find $PATH_1/version1 $PATH_2/version4 $PATH_n/versionn -type d | tr '\n' ':')

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.