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

7
votes
3answers
410 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 ...
1
vote
0answers
27 views

Having problems running a script thats built up through the script [closed]

I am currently making a script that sets variables and then runs a script. Here is a bit of what it looks like: #!/bin/bash xml='<This,is,hidden,because,of,personal,information><Id>' ...
3
votes
2answers
72 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
455 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
146 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
24 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
125 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
721 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
49 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
39 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
203 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
57 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 ...
11
votes
6answers
980 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
138 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 ...
6
votes
2answers
189 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 ...
14
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
584 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? ...
1
vote
5answers
124 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
116 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
206 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
220 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
341 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 ...
85
votes
3answers
8k views

Why is “echo” so much faster than “touch”?

I'm trying to update the timestamp to the current time on all of the xml files in my directory (recursively). I'm using Mac OSX 10.8.5. On about 300,000 files, the following echo command takes 10 ...
4
votes
4answers
684 views

Bash Scripting : Printing column data in the same row

I have written a bash script to calculate the size of a PostgreSQL database and print the output along with the date when the script was executed in a text file. The script code is as follows: ...
0
votes
1answer
280 views

How to display data in columns in two variables with the same format?

I coded the following to display data formatted in columns: str1='hello i am robert and your ma frnd' str2='thisisaverylongword thisistoohehehe andherefinishthe string hereis a other ...
10
votes
3answers
904 views

What defines the maximum size for a command single argument?

I was under the impression that the maximum length of a single argument was not the problem here so much as the total size of the overall argument array plus the size of the environment, which is ...
0
votes
3answers
626 views

echo bytes to a file

I'm trying to connect my rasberry Pi to some display using the i2c bus. To get started I wanted to manually write stuff, bytes in particular to a file. How do you write specific bytes to a file? I ...
3
votes
2answers
109 views

Command in variable one are affecting output of other variable when displayed together in UNIX

I am having two file naming Extra_info and Class_info Class_info contains data : stuId stuName stuClass S01 jagdeep First S02 harsh First S03 Roop Second S04 Kali Third ...
6
votes
3answers
686 views

adding an empty first line inside csv file

I input data into a csv by 'echo'-ing some values into another csv. I tried echo "" and in the next line echo "values" but i get intermittent empty lines.. I need empty line only at the start....
3
votes
3answers
102 views

Print a message from the left-hand side of a pipe

I want to use a variable from the main shell in a sub shell. I did: export mysql_root_password="test" ( echo $mysql_root_password ) | dialog --gauge "Working hard..." 6 50 There is no output. ...
3
votes
0answers
187 views

How to create a bash command which creates output that exactly mimics a source text file that can be pasted into bash shell where histexpand is on?

The goal is to create a bash one line command that can be copied and pasted - for instance published on a web forum - and then patches files. See it as a way to distribute a patch file by copy and ...
4
votes
2answers
888 views

print command instead of echo in linux

I simply can print a message in terminal using linux echo command. prayag@prayag$ echo "prayag works on JVM" prayag works on JVM Can I have the same output with print command. I actually went ...
6
votes
4answers
2k views

What is the difference between echo `date`, echo “`date`”, and echo '`date`'?

What is the difference between these three commands? echo `date` echo "`date`" echo '`date`' I am confused on what the differences actually are. I think that when the ' are around it means that it ...
2
votes
1answer
445 views

How to echo in shell script without executing the result

I am using this code to print all open files in the specified changelist. while read line; do echo "$line" done < `p4 opened -c $changelist` However, the line also gets executed and I get ...
1
vote
3answers
64 views

return the numeric value of a indexed variable rather than its name [duplicate]

The following piece of code illustrates my problem I'm afraid I oversimplified it way too much in the first round. #!/bin/bash dogLover=1 catLover=2 for ii in dog cat do ...
1
vote
3answers
289 views

Is there any alternative to echo daemon to display ip?

Is there any alternative to echo daemon to display ip instead of given string? For ex: my ip = 80.1.2.3 server ip = 1.2.3.4 root@my-machine bash$ telnet 1.2.3.4 Trying 1.2.3.4... Connected to ...
2
votes
1answer
87 views

How to use OSLEC with Alsa as default, not with Pulseaudio or other thirdparty package involved?

Oslec Echo canceller I have seen some packages used OSLEC and there echo cancle was very well. So for a test simulation, how could i install the OSLEC only with Alsa (i do not use PulseAudio at all, ...
7
votes
7answers
3k views

timestamp before an echo

Exists a nicer way to create timestamp in front of an echo? Currently I do it this way: #!/bin/sh if mount | grep -q /mnt/usb; then echo `date +%R\ ` "usb device already mounted" else ...
7
votes
3answers
5k views

Escape sequences with “echo -e” in different shells

I just noticed that it seems like the flag -e does not exist for the echo command in my shell on Linux. Is this just a messed up setting or is it "normal"? Some code as an example: #!/bin/sh echo -e ...
1
vote
2answers
3k views

Print line numbers of files I am searching through [closed]

I am looking for a way to print the line number of files my script is going through. I have found $LINENO but when I do echo 'Found foo in file' $(basename $foo) 'on line' $LINENO >> foo.csv ...
5
votes
2answers
1k views

Unix: how to read line's original content from file

I have a data file, the content is as follows: department: customer service section: A department: marketing section: A department: finance section: A When I read each line, I ...
1
vote
2answers
214 views

Why the inconsistency with using cat vs. echo piped to this sed command?

Inspired by this question: sed: N command does not read single line I wanted to understand why there appears to be an inconsistency between the following 2 commands: #1. echo This command produces ...
3
votes
4answers
214 views

How can I print “-n” with `echo`?

I feel really stupid, yet I can't figure how to print the string "-n" with the over 30 years-old command echo. I tried these: Michaels:Scripts$ echo -n Michaels:Scripts$ echo "-n" Michaels:Scripts$ ...
3
votes
2answers
416 views

insert text in a file using echo command [duplicate]

I am trying to insert some text in a file in the following way sudo echo "abc-abc/abc/abc" >> /etc/portage/make.conf but it give me the error Permission denied although I am using sudo ...
4
votes
1answer
235 views

Ubuntu unattended install : echo keypress to dialog

Ubuntu 12.04 LTS Server 64 My unattended-mode bootstrap.sh script contains: apt-get upgrade -y I know that during execution a primitive UI for GRUB installation will be shown which requires ...
1
vote
1answer
250 views

Cannot echo colored text when inserting in status bar in dwm

I'm using Fedora 18. I'm trying to create a custom status bar in dwm. Now what I'm thinking of is to check if the battery is under a certain level, the background of the battery region in the status ...
2
votes
1answer
85 views

'echo' eats part of the message

I want to write a script that will dump all partitions of my android device through the android debug bridge and since this is a time intensive process I want to notify the user about the progress by ...
1
vote
2answers
2k views

using bash script to output new script: need mixture of variables to be replaced and not replaced

I'm having a problem with bash variable substitution. Here's a silly example of what I am trying to do. I need to output a new script from a bash script. A line (see echo in my example) has a mixture ...
5
votes
2answers
530 views

Quoted vs unquoted string expansion

for i in $(xrandr); do echo "$i" ; done for i in "$(xrandr)"; do echo "$i"; done for i in "$(xrandr)"; do echo $i; done I understand why 1 differs from 2. But why does 3 give a different output ...