12

I have a string

server.ip=192.168.1.200

And I need to write the above statement completely into the file.

How can this be done?

This is what I'm trying to do...

set client_config = xmlrpc_server.properties
echo 'serverurl=http://'${IP}':8000' >> %${client_config}%
echo 'port=/RPC2' >> %${client_config}%

It doesn't get added to the file.

4 Answers 4

15

This worked for me

$ FOO="192.168.1.1"
$ echo "serverurl=http://$FOO:8000" >> x.conf
$ more x.conf
serverurl=http://192.168.1.1:8000

I'm using zsh. I verified it with bash as well. What's the problem you get when you do this?

Sign up to request clarification or add additional context in comments.

4 Comments

GNU bash, version 4.1.9(3)-release (i686-pc-cygwin)
more is not essential. I simply used it to display the contents. Also, what kind of system doesn't have more?
Just FYI echo adds newline character to the output file. If you don't want it use printf command it only writes the string to file and will not append newline character
@DmitryTokarev Correct. You can also use echo -n.
5

echo 'server.ip=192.168.1.200' > file in BASH.

1 Comment

When I makle the file name a variable, I get an error when trying to do this "ambiguous redirect"
1

Or

set filename=yourfile.txt
echo server.ip=192.168.1.200 >> %filename%
type yourfile.txt

If you need that line to be appended into a file. Note that double >>

Comments

0
client_config = xmlrpc_server.properties
echo "serverurl=http://${IP}:8000" >> $client_config
echo "port=/RPC2" >> $client_config

The above mentioned stuff worked. Thanks for the help folks!!

1 Comment

What shell are you using? the first line should not work in any Borne Compatible shell. Instead of: client_config = xmlrpc_server.properties you should ommit spaces, and write: client_config=xmlrpc_server.properties. Otherwise, you are trying to execute "client_confi" command with first parameter "=" and second parameter "xmlrpc_server.properties"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.