help with "echo" command

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help with "echo" command
# 1  
Old 07-24-2002
Question help with "echo" command

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]);

Here is the output:


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.

# 2  
Old 07-24-2002
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\`')
# 3  
Old 07-25-2002

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  
Old 07-25-2002
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 you may well have the same problem. It looks like it's not recognising the $ as being a variable.

You could try

unix_command="echo $__box_name"
("ksh $unix_command")
("ksh "$unix_command"")
("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 that the unix command already has it's double quotes.
# 5  
Old 07-26-2002

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.

# 6  
Old 07-28-2002
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

2. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

3. AIX

echo $varibla | mail -s "subject" "" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. UNIX for Dummies Questions & Answers

Format output from "echo" command

Hi, I have written a BASH shell script that contains a lot of "echo" commands to notify the user about what's going on. The script generates a log file that contains a copy of what is seen in the terminal. The echo statements are generally verbose, and thus extend out for quite a ways on one... (2 Replies)
Discussion started by: msb65
2 Replies

7. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

8. Shell Programming and Scripting

how to include "*" in echo command????

Hi All, I am doing one simple web tool. I have a HTML as my front end and cgi as my backend. Here my pb is when I assign the html form input to a variable in my script, it is not accepting the special char "*" to that varible. say I have a text box(Name : in_query) in html and trying to... (1 Reply)
Discussion started by: askumarece
1 Replies

9. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

10. Shell Programming and Scripting

Need a Command To display "echo command value in loop" in single line.

Hi I want to display "echo command value in loop" in single line. My requirement is to show the input file (test_1.txt) like the output file (test_2.txt) given below. Input file :test_1.txt a1|b1|4|5 a1|b1|42|9 a2|b2|32|25 a1|b1|2|5 a3|b3|4|8 a2|b2|14|6 Output file:test_2.txt... (2 Replies)
Discussion started by: sakthifire
2 Replies
Login or Register to Ask a Question