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
22
votes
6 answers

How can I check if my function print/echo's something?

I am often using echo to debug function code: public function MyFunc() { // some code... echo "OK"; // some code... } How can I check that my function print's/echo's something? (pseudo code): MyFunc(); if (
Grigory Ilizirov
  • 1,030
  • 1
  • 8
  • 26
22
votes
2 answers

echo json over command line into file

I have a build tool which is creating a versions.json file injected with a json format string. Initially I was thinking of just injecting the json via an echo, something like below. json = {"commit_id": "b8f2b8b", "environment": "test",…
David
  • 34,836
  • 11
  • 47
  • 77
22
votes
6 answers

Double quotes within php script echo

I have a line of php code that looks like this: echo ""; I would like to know how to add a font color to the text correctly. If I do this: echo…
RXC
  • 1,233
  • 5
  • 36
  • 67
21
votes
5 answers

Scripting an HTTP header request with netcat

I'm trying to play around with netcat to learn more about how HTTP works. I'd like to script some of it in bash or Perl, but I've hit upon a stumbling block early on in my testing. If I run netcat straight from the prompt and type in a HEAD request,…
romandas
  • 4,086
  • 7
  • 29
  • 33
21
votes
2 answers

Read echo'ed output from another PHP file

I want 1 PHP file to "run" (include?) another PHP file on the same server, and access its echo'ed output as a string. How do i do this in PHP? Any inbuilt functions to do this? Or any better way of executing another PHP file and getting its output?
rzlines
  • 1,417
  • 3
  • 14
  • 21
21
votes
4 answers

Creating an output file with multi line script using echo / linux

Trying to create a small script capable to write a part off the script in the output file without any changes, (as is) source file text echo " yellow=`tput setaf 3` bel=`tput bel` red=`tput setaf 1` green=`tput setaf 2` reset=`tput…
Zaza
  • 458
  • 2
  • 7
  • 15
21
votes
2 answers

Difference between echo and @echo in unix shells

What's the difference between "echo" and "@echo" in the unix world? I can't even google special characters. For example, as used here
Mako
  • 271
  • 1
  • 3
  • 8
21
votes
2 answers

Add to file if exists and create if not

I am working on a bash script that needs to take a single line and add it to the end of a file if it exists, and if it does not exist create the file with the line. I have so far: if [ ! -e /path/to/file ]; then echo $some_line >…
Mark Roddy
  • 27,122
  • 19
  • 67
  • 71
21
votes
5 answers

echo "#!" fails -- "event not found"

The following fails and I don't understand why: $ echo "#!" the following also fails with the same error message: $ echo "\#!" the error message: -bash: !": event not found Why does it fail? How should the echo be done instead?
erikbstack
  • 12,878
  • 21
  • 81
  • 115
20
votes
6 answers

How to check if string is in array with php?

I have an array that looks like the following when var_dump: array(3) { [0]=> array(3) { ["id"]=> string(1) "3" ["category"]=> string(5) "staff" ["num_posts"]=> string(1) "1" } [1]=> array(3) { ["id"]=> string(1) "1" ["category"]=> string(7)…
hairynuggets
  • 3,191
  • 22
  • 55
  • 90
20
votes
2 answers

Possible to capture PHP echo output?

So I have a function such as: public static function UnorderedList($items, $field, $view = false){ if(count($items) > 0){ echo '
    '; foreach($items as $item){ echo '
  • '; if($view){ …
Chris
  • 11,780
  • 13
  • 48
  • 70
20
votes
1 answer

echo that shell-escapes arguments

Is there a command that not just echos it's argument but also escapes them if needed (e.g. if a argument contains white space or a special character)? I'd need it in some shell magic where instead of executing a command in one script I echo the…
panzi
  • 7,517
  • 5
  • 42
  • 54
20
votes
7 answers

How to use single quote inside an echo which is using single quote

First of all, i have gone through the related questions.. haven't found any answer.. I m using this code to display a message echo 'Here goes your message with an apostrophe S like thi's '; How can i make this work, as any quote inside this echo…
Nasir Zia
  • 564
  • 1
  • 6
  • 20
20
votes
4 answers

Difference between php echo and return in terms of a jQuery ajax call

I was having trouble getting a jQuery Ajax call's success function to work properly and it was pointed out to me that the reason was that my PHP function was using return $result when I should be using echo $result. Changing the PHP function that…
marky
  • 4,878
  • 17
  • 59
  • 103
19
votes
2 answers

How can I echo commands in a tcsh script?

Yes. I know I shouldn't be using it for scripting. Yes. It is rubbish. I am indeed a fool. Nevertheless. I'd like to see the commands the script is executing, for debugging purposes. I think you get this effect with set -x or set -v in bash…
John Lawrence Aspden
  • 17,124
  • 11
  • 67
  • 110