Questions about either the shell builtin or `/bin/echo`. This tag should not be used if your question is simply about printing to the terminal, only apply it if your question is specific to the `echo` command.

learn more… | top users | synonyms

2
votes
3answers
605 views

How to stop `grep` from truncating pipe output

Is there any way to have an echo at the end of a pipe simply append to the current output rather than removing it all? For example, how can I keep the output for my cat and grep and add "END OF ...
-4
votes
2answers
5k views

Redirecting the content of a file to the command “echo”

I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo? I know I have the commands less, cat, more... but I need to do it with ...
11
votes
3answers
21k views

How do I set an environment variable on the command line and have it appear in commands?

If I run export TEST=foo echo $TEST It outputs foo. If I run TEST=foo echo $TEST It does not. How can I get this functionality without using export or a script?
2
votes
1answer
277 views

My echo command doesn't accept switches (echo -n or echo -e)

I have an echo statement in my script as below: echo -ne "Check Script"; I was expecting it to print Check Script but I am getting the below output -ne Check Script But when I run the same ...
3
votes
1answer
557 views

Printing colored text using script

When I type below command in the shell I get the OUTPUT in green color. Command echo "\033[32mCONNECTING TO abpwrk\033[m"; Output(in green color) CONNECTING TO abpwrk But if I use the same ...
4
votes
2answers
316 views

Why am I observing different behaviour of echo?

I am a bash beginner and observed the below behavior of echo #!/bin/bash x=" hello" echo $x echo "$x" Now when I run the above code I get ronnie@ronnie:~$ bash test.sh hello hello ...
8
votes
1answer
1k views

Append same text to many files using cat or echo?

How can I write the same content to many text files by using cat or echo in only one command? For example I want to write "hello" to file1 and file2. I tried: echo "hello" >> file1 file2 ...
5
votes
3answers
631 views

Construct a command by putting a string into a tty

I managed to do this echo -n "command" > /dev/tty1 The letters appear, and the cursor moves, but they are "ghosts" - if you hit enter, nothing happens (they are not in stdin). Edit: In the ...
24
votes
1answer
1k views

Why does echo >file use more real time than echo | sed >file?

The example, below, surprised me. It seems to be counter intuitive... aside from the fact that there is a whisker more user time for the echo | sed combo. Why is echo using so much sys time when it ...
9
votes
2answers
2k views

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10). Command ...
7
votes
4answers
15k views

printing colored text using echo

I know that for printing a colored text using echo, for example red color, the code is: echo -e "\e[1;31m This is red text \e[0m" and I know that in this example, 31 is code of red color and the ...
6
votes
2answers
4k views

Unexpected results testing serial loopback using echo and cat

So I have a standard RS232 serial port that is looped back to itself by simply running a wire from Tx to Rx. I'm testing loopback by running echo and cat in two separate terminals: cat /dev/ttyS1 ...
6
votes
1answer
376 views

differences between echo“”> and > command

I am new to Linux. There is something that is unclear to me. What is the difference between echo "" > logfile and > logfile ? When I run the first one, the logfile size doesn't become zero ...
3
votes
2answers
5k views

How can I trim the carriage return from text that is being piped in bash?

I'm using this command to get my last typed command: history | cut -c 8- | tail -n 2 | head -n 1 It works very well in bash, removing the line numbers, but there is one problem I have with it, (er, ...
8
votes
4answers
4k views

How can I create a file with multiple lines from the command-line?

How can I enter the following contents in a file: Hi abcd I tried using echo "Hi\nabcd" >> ab.txt, but in the file it's written as is (the \n is included, instead of a newline)
3
votes
1answer
330 views

Shell script doesn't paint last line of stdout to screen without user input

I have a shell script that's happily doing all my backup process and writing progress to stderr and stdout, with one exception — the last line doesn't get written to my terminal (if I call the script ...
1
vote
2answers
1k views

Alias Loop in csh

Why is there an Alias loop error created here: alias df 'printf "\n"; df -hP | column -t' But not here: alias df 'df -hP | column -t' I realize I could call the alias something else and still ...
15
votes
4answers
12k views

How to delete line with echo?

I know that I could delete the last three chars with: echo -ne '\b\b\b' But how can I delete a full line? I mean I dont want to use: echo -ne ...
3
votes
1answer
127 views

Why doesn't text piped into an echo get outputted?

Why doesn't this command output "1"? echo 1 | echo I imagine it working this way: 1. echo 1 (outputs 1) 2. | echo (takes the 1 as an input, then echos it) Isn't this what should happen?
4
votes
4answers
10k views

Why is echo ignoring my quote characters?

The echo command isn't including the complete text that I give it. For example, if I do: $ echo ' echo PARAM=` grep $ARG /var/tmp/setfile | awk '{print $2}' ` ' It outputs: echo PARAM=` ...
1
vote
2answers
613 views

How can I right-justify variable length output?

So I don't want this: echo "9" 9 Rather I need this, with e.g.: 4 spaces before it: MAGICK "9" 9 So if I try it with 10: MAGICK "10" 10 then it will just have 3 spaces before it. How ...
-1
votes
2answers
395 views

Copying a few lines from stdout to stderr - but only if stderr is different from stdout

I have a bash script "backup.sh", which prints out everything to stdout, including all the files that are transferred during backup. I'd like to make it possible to keep that full output, but when ...
3
votes
2answers
333 views

Weird output by echo

I was playing with echo $$ a while back. Well that displays that pid of the shell. But then I did echo ! which promptly displayed !. Then echo !! produced echo echo ! echo ! $echo !!! gave echo ...
27
votes
5answers
5k views

How to echo a bang!

I tried to create a script by echo'ing the contents into a file, instead of opening it with a editor echo -e "#!/bin/bash \n /usr/bin/command args" > .scripts/command The output: bash: ...