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

312
votes
5answers
120k views

Why is printf better than echo?

I have heard that printf is better than echo. 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 5.8 ...
0
votes
1answer
27 views

Automate commandline application for another user

i have a problem with the following command. I want to write a script that sets the vncpasswd for another user. If I run the following command it will only work for the current user. #< echo "...
2
votes
1answer
35 views

Appending a string to a file from remote ssh

I want to ssh to a node (which is passwordless) and append $spool_as_final_name true to a file /var/spool/torque/mom_priv/config. Note that is mandatory to put $ in front of the string. So, I wrote ...
3
votes
4answers
37k 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 ...
0
votes
1answer
24 views

How to print ${STR1} and $STR2 - not their contents - into a file?

I need to print expressions ${STR1} and $STR2 into a file -- not the content of the variables. How can I accomplish this using echo or printf?
6
votes
6answers
17k views

How to add new lines when using echo

Why the following command does not inserts new lines in the generated file and what's the solution? $echo "Line 1\r\nLine2" >> readme.txt $ cat readme.txt Line 1\r\nLine2
0
votes
0answers
20 views

Echo variables sshpass [duplicate]

I want to do sshpass to a server to get lots of information from it. But as some logic will be involved, I tried to create a variable inside sshpass and echo to the client (first test). It is not ...
-1
votes
1answer
23 views

Help with permissions

I am trying to set up permissions, but I don't know what exactly, as a user. Could anyone tell me which permission will allow me to execute the touch and echo commands in a directory?
6
votes
4answers
17k 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 ...
10
votes
3answers
1k 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
1answer
37 views

Echo input text amount limit?

I'm trying to do echo "foo foo foo ....[many many lines of foo here] foo" > "/Users/myname/destination.txt" through Applescript, but it returns an error when the characters in the lines of foo ...
1
vote
1answer
41 views

Piping data to a fifo with EOFs every second

I'm trying to pipe some raw binary data through to a fifo (out.pipe), and ensure that EOFs get sent at regular intervals. I do not understand why the following line will not do what I want: while ...
0
votes
0answers
37 views

get user input in terms of size (GB or MB)

I created script to calculate shmmax shmall shmmini Total_Memory_M=$(dmidecode -t 17 | grep Size | awk '{print $2}' | grep -o '[0-9]\+' | paste -sd+ | bc) Total_Memory_G=$(echo $Total_Memory_M /1024 |...
0
votes
1answer
33 views

What is special about printf over echo

I was finding length of a variable as below: `set num=123456` `echo $num|wc -c` it returned output as 7 (suppose to return 6) I did same with printf `printf "%s" $num|wc -c` it returned output ...
0
votes
0answers
32 views

Cannot telnet outside network to open port on OEL 6 machine

I have an OEL 6 server that locally is assigned IP 10.200.15.79. It is hosting a business application that uses port 1031 to send and receive information through TCP/IP. To allow this on the OEL ...
1
vote
2answers
37 views

Get the output in a formatted way

In a for loop, I am using the command: echo " Job_time is $i : Stopping the job " Sample output: Job_time is 6 : Stopping the job Job_time is 6.50 : Stopping the job Desired output: Job_time is ...
0
votes
1answer
37 views

How to rewrite `install -T /dev/null xxx`

I am trying to write in one command the following 2 ones: install -m 0755 -T /dev/null filename echo "file content" > filename Is that possible? Is there any way to avoid the -T /dev/null for "...
0
votes
0answers
13 views

running command in Mobax Terminal are there plugins that are needed

while read CTFlist; do #next we need to create ctfs padded with zeros as a variable ctfPadded=$(printf ${ctflist}00000000) #then call rc2 key as variable rc2Key="TemporaryRC2Key1" #next create a ...
5
votes
1answer
204 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 ...
14
votes
6answers
2k views

Why there is such a difference in execution time of echo and cat?

Answering this question caused me to ask another question: I thought the following scripts do the same thing and the second one should be much faster, because the first one uses cat that needs to open ...
2
votes
2answers
35 views

Get specific result from function

Is there a way to return a specific value in an echoing function? return allows me to return an exit status for the function. I need to return a more sophisticated data structure such as an array, or ...
0
votes
1answer
34 views

Why does Grave operator changes output format of the command? [duplicate]

Hello i want to ask why when i write ls -l there is new line after every row but when i assign it to a variable myVariable=`ls -l` and than echo that variable echo $myVariable i get ...
1
vote
2answers
97 views

format command output with variable and fixed space

How can I achieve this best maintaining the hierarchy on the left and aligning the size value on the right? Also, at the same time I'd like to round the size to one or two digits. I tried with printf ...
0
votes
0answers
19 views

check if a variable contains letters and exit if true [duplicate]

I am using the line below to verify that an argument do not have a letter. If it have, the script will exit. Can you help me on how I can exit the script if the argument have a letter? echo $1 | ...
-1
votes
1answer
38 views

Can I use echo to run other commands using this method? [closed]

I'm still learning unix and I need to know if there is a way to perform the following actions. Is there any way I can echo a read variable, and in the process, dissect it letter by letter, and assign ...
0
votes
1answer
48 views

Shell script that outputs chmod command for all files

On my EC2 Linux server, I blindly ran chmod 777 at directory that it turns out I should not have. There are hundreds of files in there, and I'm not sure which ones need to go back to their original ...
-1
votes
3answers
109 views

Why am I getting an error “print_unicode: line 9: printf: missing unicode digit for \u Unicode 0187” with this script

I have written them following shell script to view what the Unicode characters look like on my terminal. #!/bin/bash X=0 while [ $X -lt 65536 ]; do HEX=`bc <<< "obase=16; $X"` HEX="...
0
votes
1answer
50 views

Why does print work with awk but echo doesn't?

To sum it up.... This works: awk 'BEGIN { FS=":"; } { print $1 $3 $5; }' /etc/passwd But this doesn't: awk 'BEGIN { FS=":"; } { echo $1 $3 $5; }' /etc/passwd Being fairly new to learning ...
0
votes
1answer
40 views

Echo to file clashes with mailutils

After installing ssmtp and mailutils, writing to a file with 'echo' tries to send me an email to username@hostname. For example: Sending mail with mailutils: echo "Body text here." | mail -s "...
0
votes
2answers
63 views

using sed to modify all files in a directory and name the outputs accordingly

I want the sed command to work on all files in a directory and output the result into a new file. If f is val1.txt, the name of the output file should be val1_ended.txt -this is what I am trying to do ...
1
vote
0answers
60 views

BASH dd problem

i am trying to learn bash and now im trying to do a script for burning isos. I made the number "4" command to make sure the variables were right. the message i get when i complete my program and ...
1
vote
0answers
21 views

What does echo *? [duplicate]

Recently I was writing a bash-script and added a line: $ echo * and got an output of file names and directory names. What is the context of this list (just out of curiosity)?
1
vote
1answer
38 views

Looking for an external command that can do the same thing as echo

echo is bash builtin. Is there an external command which can do the same thing as echo? (may do more)
4
votes
2answers
237 views

How do I decode a list of base64-encoded file names?

I have a list of base64-encoded file names in the pattern of {base64-encoded part here}_2015-11-12.pdf. I'm trying to decode that list of files and return it on the command line as another list, ...
1
vote
1answer
39 views

trap echo does print not write to console when writing to file

When I terminate "CTRL+C" the following script #!/bin/bash function waa(){ for i in {1..10} do echo "start.sh: sleeping $i" sleep 1s done } trap "echo 'GAGA'" TERM waa >&...
34
votes
4answers
32k 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 '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\...
4
votes
2answers
461 views

understanding the output of echo followed by some exlamation marks

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 ...
0
votes
2answers
32 views

echoing a variable inside a variable

In my environment, the following variable is set: X=/home so echo $X gives me /home Now I set Y=$X echo $Y gives me $X. If I want to get /home using Y is it possible?
12
votes
5answers
19k 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 ...
1
vote
1answer
147 views

Is it possible to do a here-document in one line or echo verbatim?

I often find myself testing out a command (e.g. cat file | awk 'stuff') in the shell and when I'm satisfied with the way it works, I append the command to a script file. Let's say this is the command ...
1
vote
1answer
330 views

Get absolute path of file OS X

I am creating a script which will prompt the user to enter a location of file and it will convert it to an absolute path. This is what I have so far. I'm not sure how to append these together. ...
12
votes
4answers
1k views

Why doesn't echo called as /bin/sh -c echo foo output anything?

For example, while this works: $ echo foo foo This doesn't: $ /bin/sh -c echo foo Whereas this does: $ /bin/sh -c 'echo foo; echo bar' foo bar Is there an explanation?
2
votes
1answer
80 views

Run executable with variable in Bash

I have the following simple script to run an executable: ./executable.x -input input.dat << i input1 input2 i This works perfectly and all is right with the world. However, I would like to ...
5
votes
2answers
1k views

What does “echo (ls)” do in bash?

When I run echo (ls) in bash it returns: -bash: syntax error near unexpected token `ls' I understand that I should escape parenthesis or quote to get plain text output. But the result still does ...
0
votes
1answer
43 views

Whatis command (shell builtin vs executable programs)

I know that whatis command is used to output a brief description about an executable program (Command). So both whatis cd whatis type Will print: nothing appropriate (Because from my ...
0
votes
1answer
69 views

how to send data from serial port to printer?

I have a telephone system that is connected to my old Ubuntu machine and is receiving SMDR data from it. Connected to dev/lp0 is a dot matrix printer, phone system connected to /dev/ttyS0 Currently I ...
5
votes
5answers
89 views

How to print out “-E” in bash echo?

I want to execute echo and get an output like: $ export EVAR="-E" $ echo "$EVAR" -E I have stored "-E" in a bash variable, say $EVAR. If I execute echo $EVAR, echo will print out nothing. Perhaps ...
3
votes
0answers
44 views

Why only 4 chars get sent to serial port via command-line

I'm trying to communicate with NodeMCU (CP210x USB/UART) from command-line. However it does not respond to my commands. I have set the correct baudrate via stty 9600 raw. echo "gpio.write(0,gpio.LOW)"...
1
vote
2answers
55 views

Appending Echo [Password Generator]

I am creating a password generator however I am not get the passwords to append properly. Here is my script i="0" while [ $i -lt 5 ] do echo -n '#' >> passwords.txt && openssl rand ...
3
votes
3answers
732 views

How do I use a multi-character delimiter for array expansion in bash?

I'm reducing the question to (I believe) the simplest case. Let's say I have a script myscript.sh with the following contents: #!/bin/bash IFS='%20' echo "$*" If I run the command as follows, the ...