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

5
votes
3answers
691 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
30 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
25 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
192 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
47 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
965 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
129 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
185 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
569 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
110 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
86 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
187 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
198 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
298 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
641 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
235 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 ...
9
votes
3answers
696 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
396 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
104 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
515 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
98 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
181 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
741 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
1k 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
393 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
280 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
85 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
2k 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 ...
6
votes
3answers
4k 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
948 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
193 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
181 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
331 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
222 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
245 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
1k 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
485 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 ...
0
votes
4answers
648 views

echo a loop with variables command

I have several lists and want to run some commands over them. As lists are long I want to run those commands parallel to each other, hence using nohup. For every item I tried to echo a loop that ...
-1
votes
1answer
59 views

How to get all Users and echo if they work or not?

How do I get a list of users(given from the command line) with grep and output if they are logged/work or not ?
1
vote
2answers
183 views

How to make sure the shell builtin echo is invoked so that its not visible in process list?

Is this going to be visible in the process listing if the below line is executed from a command line or a shell script bash -c "echo $password" or i just need to do echo $password from within ...
0
votes
2answers
103 views

Supress expansion of * in echo

I am working on a script which dynamically executes some queries on daily basis. These queries are coming from a table in the database. Here is the sample output of the query table: ...
0
votes
1answer
98 views

the use for echo without argument in shell scripting

I have a following bash script I encountered on the web that prints the power set of a given lines of elements. p() { [ $# -eq 0 ] && echo || (shift; p "$@") | while read r ; do echo ...
1
vote
1answer
2k views

How to put value of echo pipe netcat commands into variable [duplicate]

I have this command succession: echo -ne "/dev/shm/test.sh" | netcat 89.196.167.2 4567 and let's say it return a string like, for example "Hello...bla". (on the 89.196.167.2 i have made a server ...
3
votes
2answers
312 views

echo string >> file does not work

I wrote the following script: for filename in `find . -name '*'.cpp | grep $IN_REGEX | grep -v $OUT_REGEX` do echo "Output file is $OUTPUT_FILE" count=`git log --pretty=format: --name-only ...
144
votes
5answers
47k views

Why is printf better than echo?

I have heard that printf is better than echo and I can recall only one instance from my experience where I had to use printf because echo didn't work for feeding some text into some program on RHEL ...