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

0
votes
2answers
30 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?
1
vote
1answer
37 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
53 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. ...
10
votes
4answers
822 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
38 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 ...
4
votes
2answers
597 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
26 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
24 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 ...
3
votes
5answers
62 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
23 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 ...
1
vote
2answers
40 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 ...
2
votes
2answers
42 views

Run a command stored in a variable to echo into a file

How can I get the stored command to work for the following scenario: CMD='echo "test" >> test.txt' $CMD It will work for other scenarios like: CMD='mkdir test' $CMD
-1
votes
2answers
43 views

Nested echo command in backticks

I want to know why an extra echo will print in my shell. I'm using bash version 4.2.46(1). echo `echo `echo $SHELL`` A interesting issue is if I replace '``' with $() it doesn't print extra echo: ...
0
votes
3answers
145 views

What do the `echo $?` and `ls >> $File 2>&1` commands do?

Can someone help me with understanding this. echo $? -- I know it outputs a variable of some kind... and this ls >> $File 2>&1 ---- can someone explain what this does?
1
vote
2answers
79 views

Escape characters from echo -e

I have the following in my .bashrc file I use for a log: function log(){ RED="\e[0;31m" RESET="\e[0m" echo -e "${RED}$(date)" "${RESET}$*" >> "$HOME"/mylog.txt } But when I do ...
-5
votes
1answer
28 views

question related to variable assignment in unix [closed]

Having: TIMESTAMP="date +%Y.%m.%d.%T" When I enter $TIMESTAMP on console it gives me the correct result: ~$ $TIMESTAMP 2015.11.30.15:32:39 however when I do echo $TIMESTAMP I am not getting the ...
0
votes
2answers
29 views

How do I include commands in an echo statement?

Pretty simple, but I didn't find a question on here that asked this exactly. I thought this would work but it does not. echo "Your disk usage is ${df -k -h}." How do I make the above work?
0
votes
0answers
58 views

Difference between two almost same command

Please consider two following command: $ echo ls | xargs -I cmd echo cmd | source /dev/stdin $ echo ls | source /dev/stdin What's the difference between these commands? In my machine the result of ...
2
votes
5answers
288 views

Combination generator with memory and resource management

I have this bash script, which is generating every single combination of arrays in 5 digit long: #!/usr/bin/env bash for combo in \ ...
11
votes
1answer
380 views

Why is echo matching some files twice?

$ touch file{1..12} $ echo *e{1..12} file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12 $ echo *{1..12} file1 file11 file12 file2 file3 file4 file5 file6 file7 file8 file9 ...
2
votes
1answer
46 views

Debian 8 - problem with no echo in programs

I have a problem, because some programs and functions are not working like in Debian 7. For example: reboot are not sending broadcast message, service [something] [start|stop] not echoing anything, ...
1
vote
3answers
180 views

How to make the shell execute only external echo, not the builtin one?

I have a C program which uses system() library function. Below is the source code. #include<stdlib.h> int main() { //Some code system("echo Hello World"); //some code return 0; ...
-1
votes
1answer
94 views

how to use ECHO to print out the du of a home directory in mb?

This should be a simple hw problem but I can't seem to get it to work correctly. This is an old lab that I missed a while ago (make ups are not allowed), so no I'm not just trying to get other people ...
3
votes
3answers
234 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 ...
2
votes
2answers
49 views

Command behaving differently when saved in a *.sh file

I was not able to find an answer to this question, so maybe one of you guys can help me out :) I wrote some shell scripts to help me automate things, and they work. However, what doesn't work is ...
0
votes
2answers
76 views

Initializing a variable with echo

So, I'm trying to store a part of the name of a file into a variable for other uses. So, if my file was named hello123.txt and I want to store the 123 part. So I try num= echo $file |cut -c6-8 ...
1
vote
1answer
34 views

What happens when I echo with `-e` argument?

As you can see, I have created index.php as follows: $ echo -e "<?php passthru(\$_POST[1])?>\r<?php echo 'A PHP Test ';" > index.php and then: $ cat index.php <?php echo 'A PHP Test ...
0
votes
0answers
24 views

How to reference a variable by its string “name”? [duplicate]

Say for example... #!/bin/bash a1=one a2=two a3=three for x in {1..3}; { echo -n "\$a$x "; } Actual.. $a1 $a2 $a3 Expected.. one two three How can one echo, reference, call, or what ...
2
votes
1answer
64 views

Check for related file names and delete one of them

I need to write a script that will find files that contain a string in their name. If a file exists that is the same name but without that string, I want to remove the original file. For example, if ...
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 ...
1
vote
1answer
138 views

Bash - syntax in echo

When using /bin/bash, what is the difference between the following two cases: echo $IFS echo "$IFS" I observe different outputs.
0
votes
1answer
41 views

Issues with storing an echo of a date conversion into a string variable inunix

Apologies but this question comes from a question previously raised: How can I convert a local date-time into UTC date-time? Toby has been absolutely great helping me with some conversion string-->BST ...
2
votes
3answers
1k views

echo and command substitution

I wrote a very basic script of command substitution which is below: #!/bin/bash files=$(ls *.fastq); echo $files The directory contains bunch of .fastq file and I just want to use echo command to ...
0
votes
1answer
59 views

bash: cut command produces nothing (just a blank line)

I have a problem with being able to echo a part of a string Here is a simplified version: t=no_1187985:/home/my.name/testing/no I want to echo no_1187985 only so: tt=$(echo $t | cut -d":" -f 1) ...
1
vote
1answer
403 views

Sending serial commands with echo vs screen session

I have a small LED matrix controlled by a display driver that accepts serial commands to update the display. I'm successfully controlling it via node with the node serial package, however I'd like to ...
1
vote
2answers
73 views

change colour of `echo` for particular line in shell script in Linux?

I want to change the colour of echo for a particular statement in a Linux shell script example : echo "invalid entries" echo "valid entries" echo "valid entry" I want the red color for echo ...
2
votes
5answers
3k 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
1
vote
1answer
615 views

How to echo makefile variable through Make's $(shell …)

I have a GNU makefile. The makefile has a few tests (around line 65 from the linked file): UNAME = uname MACHINE ?= $(shell $(UNAME) -m) SYSTEM ?= $(shell $(UNAME) -s) IS_X86 = $(shell echo ...
0
votes
1answer
147 views

Remove the exact same matching lines with sed

I have this bash script: sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie main/d' /etc/apt/sources.list sed -i -r '/deb http\:\/\/httpredir\.debian\.org\/debian jessie\-updates main/d' ...
1
vote
1answer
78 views

echo a colored text with tabs

I have the line below to echo values with tab between them. The text is also colored, however, some\t does not work. The output of this one below will have the first two \t not working. echo ...
4
votes
4answers
87 views

Echoing something with multiple quotes and key characters (&, $, !, etc.)

Let's say you have to echo this into a file: RZW"a4k6[)b!^"%*X6Evf How do you do it? My actual "line" to echo is a 2048 characters line.
30
votes
6answers
4k views

Is 'cat' a shell built-in or an external program?

When I use the type command to find out if cat is a shell built-in or an external program I get the output below: -$ type cat cat is hashed (/bin/cat) -$ Does this mean that cat is an external ...
7
votes
1answer
172 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
77 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 ...
4
votes
1answer
140 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
132 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
77 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
105 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
322 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
127 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?