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

-1
votes
0answers
34 views

How to merge these three task in a single command ( grep | sed | echo)

I am trying something where I parse out from the tags in a file then add back the HTML. I see everyone suggest not to do such with regEx (grep). but here it is grep -m 1 -oP ...
7
votes
1answer
133 views

Why there isn't a new line at the end of quoting a subshell and passing the results to echo?

When I do ls | grep png the output of grep is: 2015-05-15-200203_1920x1080_scrot.png 2015-05-16-025536_1920x1080_scrot.png (filename,newline,filename,newline) then, echo $(ls | grep png) outputs: ...
0
votes
2answers
37 views

displaying output in a single line

How to display output in a sinlge line. My code is: echo "total directories:" && find $DIR -type d | wc -l echo "total files:" && find $DIR -type f | wc -l output displays as ...
3
votes
1answer
45 views

echo result from subshell in zsh

In zsh, the following 2 commands results differently: a=$(</etc/hosts) && echo $a echo $(</etc/hosts) The 1st prints contents line by line, while the 2nd prints contents as a whole in ...
1
vote
2answers
45 views

echo with backspace

I am trying to figure out why this happens in bash. Ok this is easy enough. $ echo -e 'a\txy\bc' a xc Ok this is easy enough. $ echo -e 'a\txy\b\b\b\b\b\b\b\b\bc' ac xy Ok this is easy ...
1
vote
2answers
42 views

Background processes mix up order of shell script execution

Can someone explain me why the script echo one && echo two & echo three && echo four gives me [1] 3692 three four one two [1]+ Done echo one && ...
1
vote
2answers
49 views

Bash script strange behavior with echo - printf in a file

I want to print part of the content of a .csv file in another file if there is a match with some condition: The csv content is like this abc test;ABCtest.it xyz test;XYZtest.com I read the content ...
0
votes
0answers
65 views

echo `“hello terminal” > /dev/terminal` - works for /dev/tty[2-5] but not for /dev/pts/n

I'm trying to get to know the input output systems of unix/linux systems better. Since terminals and devices are implemented to interface as ordinary files, I assumed I could on any desired terminal ...
0
votes
1answer
35 views

Glob pattern argument for echo command

echo *.c in bash, treats the argument as a constant and prints *.c. How to force it to consider it as a glob pattern and print the list of files/folders ending with .c?
1
vote
1answer
40 views

How to configure the system in order beeing able to hear the sound of the \a escape character?

I read, that if I execute: echo -e "\a" a sound emerges, but frankly speaking, i executed this command several times and no sound happened.
5
votes
3answers
516 views

How to put a newline special character into a file using the echo command and redirection operator?

I would like to create a file by using the echo command and the redirection operator, the file should be made of a few lines. I tried to include a newline by "\n" inside the string: echo "first ...
5
votes
1answer
120 views

using ! character in echo

I am messing with echo and having issues with echo displaying the ! character. I tried this. echo -e "Wake!\nUp! bash: !\n!: event not found Then this # echo "Wake\!\nUp!" Wake\! Up! Well now ...
0
votes
1answer
46 views

Using echo to alter a files md5

I need to alter the md5 for some of my files, I was told to run the following echo >> /path/to/file.iso I was just wondering, What does actually do to the file. It seems to work and change ...
1
vote
1answer
39 views

Not getting the desired output for echo command [duplicate]

Below is my script. #!/bin/bash SERVERS="sl20rht00-t" #SERVERS="shcbrht01-t" USR="adm-dt-c" for host in $SERVERS do ssh -tt $USR@$host 'sudo cp /etc/sudoers /Backups/sudoers_11thmarch2015; sudo cp ...
1
vote
4answers
55 views

echo \\* - bash backslash escape behavior, is it evaluated backwards?

So in bash, When I do echo \* * This seems right, as * is escaped and taken literally. But I can't understand that, when I do echo \\* \* I thought the first backslash escaped the second one ...
0
votes
1answer
48 views

Why does the input to xargs is 1 string but without is strings in separate line?

I am trying to pipe file to rm via xargs. I understand that what I am tryng to do could be done by git clean but I am practicing the cli. I tried this: for files in $(git status --porcelain| sed ...
-1
votes
1answer
38 views

sudo issue during echo something to a root file [duplicate]

I have a problem, during write something into a root file: $ ll /sys/bus/usb/devices/3-2/power/wakeup -rw-r--r-- 1 root root 4096 Feb 16 17:28 /sys/bus/usb/devices/3-2/power/wakeup $ sudo echo ...
0
votes
1answer
48 views

How do I add a \n to the end of the record on file using AWK

I have a file that can contain 1 or many lines oracle1.txt oracle2.txt oracle3.txt How do I using AWK put a \n after the last line only so it will show oracle1.txt oracle2.txt oracle3.txt\n I ...
0
votes
3answers
639 views

create XML file using bash script

I want create simple xml file using bash script ( not with dom ) but when I set value in the line then echo print the $lorem word and not the val lorem=LOL echo '<root><foo ...
2
votes
0answers
61 views

Is there a difference between double quoting a variable or a whole line in echo

When you type, for example, echo Variable "$var" is not initialised. and echo "Variable $var is not initialised." the front end result is the exact same (as far as I know, at least). But I was ...
2
votes
1answer
113 views

Avoid backslash expansion with echo in dash

First create a file with this exact content: a\nb I named this file foo, if I run the following, it prints the exact content of the file: bash -c 'bar=$(cat foo);echo "$bar"' But if you run it ...
1
vote
1answer
74 views

Echo newline with quotes [duplicate]

For: $hello="hello > world" Why does echo not print the newline for: echo -e $hello But if I put $hello in quotes it does. $ echo "$hello" hello world Is this because of ANSI-C Quoting? ...
5
votes
1answer
183 views

echo colored text which changes colors dynamically

Is there any way that i can print a colored text on console which keeps on changing its colors dynamically(with or without a specified time interval) just like some greeting cards in which the ...
1
vote
1answer
86 views

how to `echo` 'formatted' man page of some command to text file [duplicate]

When I execute echo `man ls` > tem.txt I get unformatted output in the text file, I mean output without any new lines, just continues sentences. How do I get formatted output ? For example, ...
1
vote
2answers
32 views

How would I loop this command?

A snippet of my code is shown below. The script currently closes if its not able to find the path. [echo "could not find $REPLY, ensure the path is correct and try again"] Instead I would like it ...
1
vote
2answers
186 views

How do I expect 'echo -e “? \c”'?

I'm an absolute newbie to the UNIX world and have been asked to write a script that interacts with another one - but I'm stuck. The script that I interact with echos the following and I need to send a ...
1
vote
3answers
164 views

How to print new lines at the end of functions?

If I type echo hello, my terminal looks like this: My-Computer:~ user$ echo hello hello My-Computer:~ user$ But if I have a function like this stringen () { cat /dev/urandom | env LC_CTYPE=C tr ...
6
votes
4answers
531 views

Back to back Pipes into a Command

Is there a way to pipe back to back values into a command? e.g. If I can command.pl and want to pipe in response, then y to confirm (because it doesn't have a way to auto confirm)? I've tried echo ...
7
votes
3answers
494 views

in Bash, how to not include extra arguments in an alias?

I am trying to do something like alias ftp='echo do not use ftp. Use sftp instead.' just so that ftp will not be accidentally used. But I noticed that ftp abcd.com will cause the command to ...
3
votes
2answers
418 views

What is the format for piping a message into sendmail?

I am using the following command to create messages on the fly, and send them: echo "Subject:Hello \n\n I would like to buy a hamburger\n" | sendmail email@example.com It seems that when you send ...
6
votes
3answers
517 views

How do I print '-e' with echo?

I know that echo -e is not an ordinary command. I have tried echo '-e' and echo \-e but they still don`t work.
3
votes
2answers
335 views

Bash - echo line by line, ignoring the space between the lines

I had read the post on: bash - replace space with new line, but it does not helped to solve my issue. [My Directory] [root@testlabs Config]# ls Archive Backup_Files config_file.tgz ...
0
votes
2answers
52 views

zsh function output removes leading whitespace

Consider the following two commands and their outcome: 14:57 : echo $(echo " ABC") ABC 14:57 : echo " ABC" ABC Version of zsh: zsh 5.0.5 (x86_64-apple-darwin14.0) Why does the first one ...
4
votes
3answers
1k views

Add text with echo but start with new line if file not empty

I'm trying to create next script echo "#!/bin/sh" >/script echo "del x.txt" >>/script witch is ok if /script file is empty, if not - will append first line to last text #!/bin/sh del ...
14
votes
4answers
2k views

What does echo $-1 display?

What does the output of echo $-1, echo $-2, echo $-3.. mean? On one of my Linux boxes, it shows me: echo $-1 imsBEl1 echo $-2 imsBEl2 And on another Linux box, it shows: echo $-1 himBH1 echo $-2 ...
5
votes
3answers
769 views

Why does “$ sudo echo 'yo' ” work even though echo is a shell built in function? [duplicate]

I understand that sudo cd /directory will return: sudo: cd: command not found because cd is a shell builtin and not a binary. But then, why does sudo echo 'this is a test' works fine? What ...
0
votes
0answers
367 views

BC returns syntax error

#!/bin/bash cd ~/simplesim-3.0/benchmarks INSTS=$(grep "sim_num_insn" ./anagram.txt | awk '{print $2}'); IL1_ACCESSES=$(grep "il1.accesses" ./anagram.txt | awk '{print $2}'); IL1_MISSRATE=$(grep ...
0
votes
1answer
144 views

What is the difference between the built in echo command and /bin/echo? [duplicate]

I was playing around with the type and which commands and I discovered something strange. type either returns the path or says that a command is a Bash built in. which either returns the path or ...
3
votes
2answers
214 views

How do I echo a lot of content in a bash script?

I would like to do echo "[this thing]" This thing is \documentclass{article} \usepackage{rotating} \usepackage{pdfpages} \usepackage{verbatim} \usepackage{amsmath, amsfonts, amssymb, textcomp, ...
1
vote
1answer
124 views

./a.out && echo $? only prints return value if return = 0

echo $? in the following scenario does not display the return value, i.e. 1. echo "int main() { return 1; }" > foo.c gcc foo.c && ./a.out && echo $? However, echo $? works when ...
12
votes
6answers
1k views

What is the reverse of echo -e?

If I have a string with nonprintable characters, new lines, or tabs, is there a way I can use echo to print this string and show codes for these characters (e.g., \n for new line, \b for backspace)?
4
votes
3answers
219 views

How do I capture stdin to a variable without stripping any trailing newlines?

In a shell script... How do I capture stdin to a variable without stripping any trailing newlines? Right now I have tried: var=`cat` var=`tee` var=$(tee) In all cases $var will not have the ...
5
votes
2answers
265 views

echo of a string with an exclamation point

Here are what I put in bash and the results I got about 'echo': $ echo '!$' !$ $ echo "!$" echo "'!$'" '!$' I'd like to know how 'echo' deals with the second input. It seems to me that ...
15
votes
3answers
1k views

why 'echo --help' doesn't give me help page of echo?

I tried 'man echo' in Bash and it told me that 'echo --help' will display help then exit, and similarly, that 'echo --version' will output version and exit. But why it doesn't work ? 'echo --help' ...
9
votes
3answers
665 views

Why does “wc -c” print a value of one more with echo?

When running echo abcd | wc -c it returns 5. But the word abcd is only 4 characters long. Is echo printing some special character after the word abcd? And can I prevent echo from printing that? ...
2
votes
5answers
262 views

How to overwrite stdout using echo? [closed]

We know to overwrite bar.txt, we can use this: echo "foo" > bar.txt but how can we overwrite to the standard output? I tried this command: echo "foo" > but it failed. I want this because ...
2
votes
2answers
235 views

Read Multiple Entries from an Input File

I wrote a program in Fortran that asks me for latitude and longitude and the name of the output file every time I run it. It works great. What I have been meaning to do is run this program for the ...
3
votes
2answers
299 views

How do I echo an expression with both single and double quotes?

I have tried many things, but I'm new to the shell. Is it possible to have both double and single quotes within an echo? I want to generate echo "scan 'LPV',{FILTER => "(PrefixFilter ...
3
votes
3answers
322 views

Split a returned block of text into lines in terminal?

When I give commands like echo $PATH or which program, I often get a very large block of text consisting of may directories. This is fairly useless, if I am for example, looking to see if there is or ...
3
votes
1answer
561 views

Prevent hanging of “echo STRING > fifo” when nothing is reading that FIFO

When I echo something to a named pipe made with mkfifo, it hangs if no process is reading from that pipe. How can I prevent that, i.e., stop that from hanging? And by the way, why is that hanging ...