Pass RegEx to java program in bash script


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Pass RegEx to java program in bash script
# 1  
Old 05-08-2019
Pass RegEx to java program in bash script

I can't seem to get this right. I've tried it every way imaginable using every trick I see on stackexchange and such. No luck. So nothing major here, something like:

Code:
#!/bin/bash

SEARCH="ARG1 ARG2 '((^EXACT$)|(.*InTheMiddle*)|(^AtBeginning*))'"
java -cp /my/class/path MyClassName $SEARCH
exit $?

For the java program to work, the single quotes must be in there. I've tried escaping them all kinds of ways but can't get the script to call the java class in a way that is simply what it is. From the command line I can call the java class with no issue. Any help? Definitely not worth the time I've been spending on this... Thanks - Eric
# 2  
Old 05-08-2019
The code that I would EXPECT to work is:

Code:
#!/bin/bash

SEARCH='ARG1 ARG2 "((^EXACT$)|(.*InTheMiddle*)|(^AtBeginning*))"'
java -cp /my/class/path MyClassName $SEARCH
exit $?

But bash -x shows that performing:

Quote:
+ java -cp /my/class/path MyClassName ARG1 ARG2 '"((^EXACT$)|(.*InTheMiddle*)|(^AtBeginning*))"'
So it puts my double quotes in single quotes. I've tried all sorts of other stuff to no avail. Anybody have an answer or even a work around?
# 3  
Old 05-08-2019
Looks good for me. Did you try "$SEARCH"?
This User Gave Thanks to RudiC For This Post:
# 4  
Old 05-09-2019
Ahhhh, you got it! Had to separate the first 2 arguments that didn't need quoted from the last argument and surround the last one in quotes when sending it. Thank you!!!

Code:
#!/bin/bash

SEARCH1='ARG1 ARG2'
SEARCH2='((^EXACT$)|(.*InTheMiddle*)|(^AtBeginning*))'
java -cp /my/class/path MyClassName $SEARCH1 "$SEARCH2"
exit $?

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Triggering UNIX Script from a JAVA program

Hi I am trying to implement one program, where JAVA needs to trigger the backend UNIX script. Tried with options like String cmdArray = {"/bin/ksh","-c","/SCRIPT_ABSOLUTE_PATH/sampleScript.ksh /FILE_ABSOLUTE_PATH Test_File.dat TEST E SFTP"} When I trigger the script from front end with... (1 Reply)
Discussion started by: karumudi7
1 Replies

2. Shell Programming and Scripting

Executing the shell script through java program

Hi Team, Can you pls advise in java how can we call a shell script, actly I have a shell script at the following location /opt/dd/ajh.sh now I can execute this script by opening the session through putty by entering the servers details and password and then navigating to the following... (2 Replies)
Discussion started by: punpun777777
2 Replies

3. UNIX for Dummies Questions & Answers

how to pass input from c program to shell script?

Hello.. I am developing a Graphical User Interface using GTK. As part of our project I need to take inputs from GTK entries and pass those inputs to shell script and use them in shell script. The problem which struck me is only limited number of inputs are getting passed to shell script. For now... (14 Replies)
Discussion started by: kalyanilinux
14 Replies

4. Shell Programming and Scripting

How to pass the environment name while calling java program from unix script?

Hi, I'm trying to test one unix shell script in dev environment. But I'm not sure how to pass the environment in my java program calling code. I'm trying to use -DconsumerEnv="DEV" but unfortunately I get 'null' while trying to print the value from java class. System.out.println("Environment: "+... (4 Replies)
Discussion started by: Pramit
4 Replies

5. Shell Programming and Scripting

How to make bash wrapper for java/groovy program with variable length arguments lists?

The following bash script does not work because the java/groovy code always thinks there are four arguments even if there are only 1 or 2. As you can see from my hideous backslashes, I am using cygwin bash on windows. export... (1 Reply)
Discussion started by: siegfried
1 Replies

6. Shell Programming and Scripting

Call java program from shell and pass values

Hi All, Can anybody please help me with how can i call my java program from shell and also pass parameter along with it so that the program can interpret the value/int and update the database. Thanks in advance Neha (1 Reply)
Discussion started by: Neha Goyal
1 Replies

7. Shell Programming and Scripting

Can we pass an array of strings from a Perl Program to a Shell Script?

Hi Folks, The subject is my question: Can we pass an array of strings from a Perl Program to a Shell Script? Please provide some sample code. Thanks ---------- Post updated at 11:52 PM ---------- Previous update was at 11:43 PM ---------- I got it. Its here:... (0 Replies)
Discussion started by: som.nitk
0 Replies

8. Shell Programming and Scripting

Pass string from shell script to java

Hi, I,m writing a program in shell script and currently this script is calling a java program. I have a problem to pass string variable from my shell script to the java program. I don't know on how to pass it and how the java program can call what I have pass from the shell script. This is... (3 Replies)
Discussion started by: badbunny9316
3 Replies

9. Shell Programming and Scripting

How to invoke a perl script from java program

Hi: I need to invoke a perl script from a java applet program in UNIX operating system.. Can you please suggest me!!! (4 Replies)
Discussion started by: grajesh_955
4 Replies

10. Shell Programming and Scripting

Invoke java program in script

Hey all, My boss tasked me with the job to write a script which would invoke various java programs, the thing is I don't know much about shell scripting so would you experts help me out? Here is the requirement - 2 applications written in java: App_A and App_B -... (0 Replies)
Discussion started by: mpang_
0 Replies
Login or Register to Ask a Question