![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| echo "ABC" > file1.txt file2.txt file3.txt | ganapati | UNIX for Dummies Questions & Answers | 4 | 01-29-2008 09:36 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-19-2007 10:52 PM |
| "sed" to check file size & echo " " to destination file | jockey007 | Shell Programming and Scripting | 6 | 11-13-2007 06:00 PM |
| [[ $(date +%Y) == 2007 ]] && echo "Happy New Year" | ripat | What's on Your Mind? | 2 | 01-02-2007 05:12 AM |
| Unix "at" / "Cron" Command New Problem...Need help | Mohanraj | UNIX for Dummies Questions & Answers | 3 | 01-26-2006 05:08 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I was wondering how i could integrate the "echo" command into a java program. Here is my code:
String boxname=""; String[] box = new CmdExec().run("ksh \"echo $__box_name\""); boxname = (box[box.length-1]); System.out.println("BoxName2:"+boxname+"\n"); Here is the output: BoxName2:$__box_name I have set $__box_name=testbox and was expecting the output to be "testbox" The command took $__box_name in as plain text and not as a variable. How do I get the command line to return the value of "$__box_name?" Any help would be much appreciated. Brian |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
May well have something to do with your quotes... you have got
("ksh \"echo $__box_name\"") Because you've got all double quotes....your basically looking at 3 things in our brackets.. "ksh \" echo $__box_name\ "" Now this may be something in java you can do.....I've no idea, but in terms of the Unix method you should use a combination of single and double quotes. Note also that where double quotes are supplied the variable expansion can occur...with single it won't. So may you could try ('ksh \"echo $__box_name\"') Alternatively you might look at backticks..... ('ksh \`echo $__box_name\`')
__________________
Pete |
|
#3
|
|||
|
|||
|
Thanks for all of your help..but it still won't work. Java strings need to be started with the "double quote" If you use the 'single quote' it returns an error. I am just so frustrated because this is such a simple thing, but I can't get it to work. I also tried using the backlash, double quote- single quote combination, but that only gives me the return value as an integer. Here's the funny thing though. if I use "hostname" as the command it returns the actual hostname...not "hostname" in text. Is there a way of combining the "echo $__box_name" command into a one word execution? This is my only alternative solution. Thanks for all your help
|
|
#4
|
|||
|
|||
|
Have you tried the double quotes around the entire command - with the backticks on the inner bit?
You can combine "echo $__box_name" into a one word command - although this will be a variable also....so you may well have the same problem. It looks like it's not recognising the $ as being a variable. You could try __box_name=theserver unix_command="echo $__box_name" ("ksh $unix_command") or ("ksh "$unix_command"") or ("ksh \"$unix_command\"") I'm just not sure how the java command is syntaxed! Alternatively you could look at making the unix_command=single quote double quote command double quote single quote..so that the unix command already has it's double quotes.
__________________
Pete |
|
#5
|
|||
|
|||
|
Hi Peter,
I actually did try double quotes around the entire string and then backticks around the actual command only to get a ksh error. It says that `echo cannot be found. I also tried doing what you said by combining the "echo $__box_name" into a variable, but I still get the same problem. I just don't know why it takes in the "echo" command but does not recognize the $__box_name as a parameter. If echo works, the $__box_name should as well. Right now I am using a script that is called by the java program to execute the command. It is extremely inefficient, but at least it works until I can figure out the syntax. Thanks for your help though..I really do appreciate it. If you have any other solutions, please toss them my way. Thanks again. Brian |
|
#6
|
|||
|
|||
|
I'm afraid we're well out of my league here.
The only other thing I would try would be to do with the backslash... i.e. don't use it...but again that may be a java essentail thing - I don't know. The backslash will mean take the next char as a literal....but unix you can use the quotes around the echo to specify the echo text... so apart from that you're on yuor own...unless there is some java guru here who can assist?
__________________
Pete |
|||
| Google The UNIX and Linux Forums |