Questions tagged [echo]

Simple function outputting text. Exists in script languages.

echo is mainly used in batch (cmd). An example would be:

echo hello world

which prints "hello world" to the terminal.

The output by default prints directly to the command line, however, it may be piped into a following command as an input. This can be very handy and allows for interoperability between different processes/languages.

5742 questions
27
votes
8 answers

PHP Echo text Color

How do I change the color of an echo message and center the message in the PHP I've written. The line I have is: echo 'Request has been sent. Please wait for my reply!';
The Woo
  • 17,809
  • 26
  • 57
  • 71
26
votes
4 answers

Bash: add string to the end of the file without line break

How can I add string to the end of the file without line break? for example if i'm using >> it will add to the end of the file with line break: cat list.txt yourText1 root@host-37:/# echo yourText2 >> list.txt root@host-37:/# cat…
Crazy_Bash
  • 1,755
  • 10
  • 26
  • 38
26
votes
4 answers

echo $JAVA_HOME not returning jdk location

When I type in echo $JAVA_HOME, I get $JAVA_HOME instead of the location of the jdk. I set the path from the environment variables correctly: Variable name : JAVA_HOME Variable value: C:\Program Files\Java\jdk1.7.0_25 what am I doing wrong?
Aamare
  • 283
  • 2
  • 4
  • 5
26
votes
4 answers

PHP if shorthand and echo in one line - possible?

What's the best, preferred way of writing if shorthand one-liner such as: expression ? $foo : $bar Plot twist: I need to echo $foo or echo $bar. Any crazy tricks? :)
Wordpressor
  • 7,173
  • 23
  • 69
  • 108
25
votes
4 answers

How to echo a custom object in PHP?

Given a particular class, TheClass, with an instance foo, is there any way to have PHP echo foo; in a customized manner? class TheClass { public $Name; public $Number; function MrFunction() { /* bla bla bla */ } } $foo = new…
25
votes
1 answer

how to pass "one" argument and use it twice in "xargs" command

I tried to use the xargs to pass the arguments to the echo: [usr@linux scripts]$ echo {0..4} | xargs -n 1 echo 0 1 2 3 4 the -n 1 insured that the xargs pass 1 arguments a time to the echo. Then I want to use this aruments twice, however the…
spring cc
  • 937
  • 1
  • 10
  • 19
24
votes
5 answers

Scala equivalent of python echo server/client example?

All the "server" example in scala use actors, reactors etc... Can someone show me how to write a dead simple echo server and client, just like the following python example of Server and Client: # A simple echo server import socket host = '' port…
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
24
votes
3 answers

Powershell Echo Statement + Variable In One line

I'm running a script, and I want it to print a "statement + variable + statement" at the end [when successful]. I've tried a few thing but it always returns as 3 separate lines, instead of one. The Echo "" before and after is just to make it easier…
physlexic
  • 826
  • 2
  • 9
  • 21
24
votes
4 answers

Echo some command lines in a shell script (echo on for single command)

In shell scripts I would like to echo some of the major (long running) commands for status and debug reason. I know I can enable an echo for all commands with set -x or set -v. But I don't want to see all the commands (specially not the echo…
Den
  • 547
  • 1
  • 6
  • 15
23
votes
3 answers

What is the ASP.Net equivalent to PHP's Echo?

I want to 'echo' a string separated by delimeters like: sergio|tapia|1999|10am the Body of an HTML page. How can I achieve this? Thank you!
delete
23
votes
3 answers

Why $'\0' or $'\x0' is an empty string? Should be the null-character, isn't it?

bash allows $'string' expansion. My man bash says: Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if…
oHo
  • 51,447
  • 27
  • 165
  • 200
23
votes
6 answers

Echo command, and then run it? (Like make)

Is there some way to get bash into a sort of verbose mode where, such that, when it's running a shell script, it echoes out the command it's going to run before running it? That is, so that it's possible to see the commands that were run (as well…
mjs
  • 63,493
  • 27
  • 91
  • 122
23
votes
5 answers

How to make echo interpret backslash escapes and not print a trailing newline?

I would like to use echo in bash to print out a string of characters followed by only a carriage return. I've looked through the man page and have found that echo -e will make echo interpret backslash escape characters. Using that I can say echo -e…
seanwatson
  • 1,053
  • 1
  • 9
  • 12
22
votes
4 answers

How to prevent echo in PHP and catch what it is inside?

I have a function ( DoDb::printJsonDG($sql, $db, 1000, 2) ) which echos json. I have to catch it and then use str_replace() before it is send to the user. However I cannot stop it from doing echo. I don't want to change printJsonDG because it is…
ilhan
  • 8,700
  • 35
  • 117
  • 201
22
votes
6 answers

How to print a bash array on the same line

I am reading in filetype data into a bash array and need to print its contents out on the same line with spaces. #!/bin/bash filename=$1 declare -a myArray readarray myArray < $1 echo "${myArray[@]}" I try this and even with the echo -n flag it…
Alec Beyer
  • 263
  • 1
  • 2
  • 7