A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [echo]

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.

Filter by
Sorted by
Tagged with
0
votes
3answers
78 views

Can echo be combined to produce a single result of .*/ and */?

The echo command outputs differing results based on the expression passed to it. The working directory is /home/etc $ echo .*/ / ../ .cache/ .config/ .gnupg/ .local/ .mozilla/ .ssh/ $ echo ./* ./...
0
votes
2answers
66 views

Why do I Get a Blank Output When echoing $variable? [duplicate]

I'm just trying to echo a variable stored in a file. When issuing the echo $variable command I'm getting a black area with no output. I don't understand why. Content of file1: name="Jhon" My ...
0
votes
1answer
71 views

How to solve the beep sound problem on linux?

Currently I am using Linux mint. I tried the following command on the command line. echo -e "\a" As we know this command should produce a beep sound, but on my Linux machine nothing happened, it ...
0
votes
1answer
153 views

“echo: write error: invalid argument” writing to sysfs

From the instructions for setting up bcache: echo cset.uuid > /sys/block/bcache0/bcache/attach What happens: root@gentooserver ~ # echo 45511b33-6bb8-42d5-a255-3de1749f8dda > /sys/block/...
0
votes
1answer
314 views

Understanding the output of cut -f [duplicate]

Thank you for your patience I am new to linux and I wanted some help understanding how I can parse the output of the cut command. So, currently I have a variable x=$(discover nginx --human=nood | ...
0
votes
2answers
64 views

Cut works with echo but not without it

So I am trying to extract an output similar to x=($discover nginx --human=nood) which gives me an output like i-03099 nginx IP noodlefish pip b4b966d280546c6b070f5f952c281d3294308048 ...
0
votes
1answer
20 views

Multiline Variable add a Tab before each Newline

The Following snippet uses a custom function HexNewLine which basically converts the hexdump and breaks at the character 0x0a $ echo -e "\t{ > "dependencies": { > "prettier": { > ...
1
vote
1answer
33 views

Getting different value for ps command when assigning to a variable

I get a different output when I assign this to a variable. Why is this? #!/bin/bash P=$(ps -ef | grep ${APP} | grep -v grep | wc -l) echo ps -ef | grep ${APP} | grep -v grep | wc -l echo $P Output:...
0
votes
3answers
19 views

Generate tex file containing all filenames in a directory

I have a folder containing 95 tex files. I need to create a tex file all.tex that contains the following code: \documentclass[10pt]{article} \begin{document} \input{file1.tex} \input{file2.tex} ... \...
1
vote
0answers
25 views

BSD netcat how to terminate after sending command?

echo "test" | nc -N -U example.soc How can I have this terminate once it has successfully sent the message over? According to the man page: There should now be a connection between the ports. ...
0
votes
0answers
23 views

How do I change the boot text?

So after GRUB and before sddm I see: Starting version xxx.xx-x-arch /dev/nvme0n1p2: clean, xxx/xxx files, xxx/xxx blocks How do I add another line of text under them? Like via echo or somehow? My ...
2
votes
1answer
41 views

How can i put the gcc warning messages in a text file? [duplicate]

I wished to know if someone knew how to put the compilation warnings of GCC in a text file ? For example : I wrote (willingly) a undefined function foo(). So gcc tell me : warning: implicit ...
0
votes
1answer
33 views

Why does xargs seem to handle delimiters differently if -I is set

xargs -n1 -I '{}' echo '{}' <<< "foo bar baz" prints foo bar baz while xargs -n1 echo <<< "foo bar baz" prints foo bar baz What causes this behavior?
1
vote
2answers
68 views

How to cat multiple lines with indentation in bash function?

I have a bash function yumtelegraf() { cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo [influxdb] name = InfluxDB Repository - RHEL \$releasever baseurl = https://repos.influxdata.com/rhel/\...
8
votes
8answers
556 views

How to list all non-environment variables in bash?

I'd like to echo all non-environment variables (all self-declared variables), in Bash 3.2.52. This command to print all variables gave me output I can't understand that seems to me to conflict with ...
0
votes
1answer
65 views

How to print output to look like stairs?

My code is this in my shell script file: for i in {0..3} do COLOR_Value="\033[1;3"$i"m \t Hello World" echo -e $COLOR_Value done The output is this: (Each Hello World changes color as it ...
1
vote
1answer
55 views

echo -e “word\b” not working as expected

According to man: If -e is in effect, the following sequences are recognized: \b backspace So I would expect echo -e "word\b" to produce wor output. But yet: $ echo -e "wor\bd" wod $ ...
0
votes
3answers
68 views

How to print the exact result of a command to a file

Context I have a file my-cmd: echo '<some data...>\\<some other data...>' Basically, I want to redirect the output of this command to a text file: ./my-cmd > file.txt Question My ...
2
votes
3answers
68 views

Echoing from a variable in a specific part of a string

I am trying to make a command for having a nice-looking git log. Say I have the following: git log --color --pretty=format:"%C(cyan)<%an>" --abbrev-commit What I would like to do is to make a ...
1
vote
2answers
79 views

awk not recognized in shell script

I'm trying to do floating point arithmetic in a shell script. I learned that awk can do it on the command line, but the way it works there does not seem to carry over to a shell script. When I type ...
0
votes
2answers
63 views

How to assign “-e” to a variable in bash

I'm trying to assign -e to a variable in Bash 4. But the variable remains empty. For example: $ var="-e" $ echo $var $ var='-e' $ echo $var $ var="-t" $ echo $var -t Why does it work with -t, ...
5
votes
4answers
216 views

Show stdout containing \n with line breaks

The output from an executable (cURL) contains \n. How can such output be displayed with line breaks? Say the output from an executable is tCL\n1523 memo\n, piping to printf does not show line breaks. ...
2
votes
4answers
829 views

Next command output on the same line? Bash script

I have the following simple script: echo "-------------------------- SOA --------------------------------" echo " " echo -n " ---------> "; dig soa "$1" +short | awk '{print $3}' The output is ...
0
votes
2answers
74 views

Issue with `echo` in bash when looping over output of python script

Given the python script if __name__ == '__main__': print("first") print("second") print("third") the bash script #!/usr/bin/env bash declare -a choice=$( python3 test.py ) echo "You ...
3
votes
1answer
109 views

Can I set my bashrc to echo $? after a particular command?

I'm familiar with setting simple aliases in my .bashrc, and think it might be capable of doing what I want, but not quite sure how to do it. The desire: always echo $? after a particular program ...
2
votes
2answers
486 views

Creating a file in Linux? (Touch vs Echo)

I'm pretty new to Linux in general, so I'm not too familiar with do's and don'ts of some commands. I wanted to create a file and noticed that: touch file.txt ` creates a file, but so does: echo &...
0
votes
1answer
808 views

How to print out each command argument with echo? [duplicate]

According to this answer ... A command is split into an array of strings named arguments. Argument 0 is (normally) the command name, argument 1, the first element following the command, and so ...
1
vote
1answer
28 views

how to print hyphen in double quotes along with other strings

cat inv_summary_1.txt | while read -r aLine do F1=`echo "$aLine" | cut -d "," -f1` F2=`echo "$aLine" | cut -d "," -f2` echo " 0 RUN_ID STR [0] \"${F2}\" " done 191245204696,REG-...
0
votes
0answers
18 views

how to post cronjob output in terminal (Ubuntu) [duplicate]

I'm just a beginner with linux A have a simple test_script with echo "testtesttest" And a cronjob with * * * * * /home/<user>/test_sript and MAILTO="" to get this testmessage every minute. ...
1
vote
1answer
455 views

bash echo color to textfile [closed]

How can I write colored text using bash? RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' greprc=$? if [[ $greprc -eq 0 ]] ; then echo -e "${GREEN} converged${NC}" >>log else echo -e "${RED}...
5
votes
2answers
1k views

Print one file per line using echo

How can I print a list of files/directories one-per-line using echo? I can replace spaces with newlines, but this doesn't work if the filenames contain spaces: $ echo small*jpg small1.jpg small2.jpg ...
0
votes
3answers
71 views

I have if else question but I am not sure the answer is true? [duplicate]

I am running this on Linux: $ number=4 $ test $number -eq 4 $ echo $? 0 $ test $number -lt 2 $ echo $? 1 Are the results (0 and 1) true ?
0
votes
1answer
78 views

echo return an empty variable $

I have this command echo "<?php $x=$_GET['x']; echo $x;?>" > x.php the output file x.php is: <?php =['x']; echo ;?> Has that any relation to the $ variable? and how do I avoid ???, ...
2
votes
2answers
56 views

Linux Bash: Variable to another variable [duplicate]

i have this: echo $MSG | sed -e $'s/;/\\\n/g' I want to put the result of that sed in a new variable called $MSG2 Something like: $MSG2=echo $MSG|sed -e $'s/;/\\\n/g' How can i do it? Thank you!...
0
votes
1answer
95 views

How to properly write a string to a named pipe and the difference between echo and printf

Problem: I need to send a command to a named pipe and need to ensure only the command is sent and not any errant or "fat-fingered" characters. Example: I have been using the following: echo "...
-2
votes
1answer
104 views

What does (($count+1)) do in this script?

Can anyone tell me what the purpose/action is of this area right here circled in neon green color? I would like to know its purpose in terms of what it does in a script. while IꓝS= read -r line; do ...
4
votes
3answers
5k views

Using `printf` to print variable containing `%` percent sign results in “bash: printf: `p': invalid format character”

I want to use printf to print a variable. It might be possible that this variable contains a % percent sign. Minimal example: $ TEST="contains % percent" $ echo "${TEST}" contains % percent $ printf ...
0
votes
0answers
42 views

Why does single quotes around arguments fail to prevent “syntax error near unexpected token '('”? [duplicate]

I read that surrounding command line arguments with single quotes is necessary when the command line argument is a string that contains parentheses. However using single quotes around the following ...
0
votes
1answer
64 views

How to “echo” colored messages without “-e” option nor intermediate variable?

I really struggle understanding the behavior of echo (and others such commands) while processing ANSI escape codes to print colored messages. I know I can use the -e option like this: echo -e "\e[...
1
vote
1answer
95 views

File Descriptors and Redirection

Several resources state the file descriptor 0 is connected to the keyboard. I have learned that echo does not receive input from stdin (or 0). This feels contradictory to me. When I run echo foo I'm ...
0
votes
1answer
212 views

echo strings but extra question mark was added to the output

Strange "?" got added to the filename output. SCRIPTS="/path_to_script/" SUMMER=`cat /path_to_file/summer.txt` for i in ${SUMMER}; do cat <<- EOF > $SCRIPTS/20190430_$(echo ${i})_step4.r #...
2
votes
1answer
59 views

Newline character produced by `echo`, is it always there when using no options, regardless of shell?

Although I have read Stephane's answer concentrated on basically all aspects of echo vs printf, I am unsure if it also answers my question, which stands: The newline character produced by echo, is it ...
8
votes
3answers
1k views

Echoing a tail command produces unexpected output?

This command, when run alone, produces the expected result (the last line of the crontab): tail -n 1 /etc/crontab However, when I run it as part of an echo command to send the result to a file, it ...
0
votes
1answer
110 views

printf and echo -e are giving different results

I am using \0n escape sequence with echo -e and printf where n is the octal value of the ASCII character to be printed. When i used the statement echo -e "\0101" the shell is printing character A but ...
0
votes
0answers
178 views

How does this echo command work? “echo > file.txt Hello” [duplicate]

I know you can redirect the output of echo to a file using this syntax: $ echo "Hello" > file.txt But I recently discovered a different way of producing the same output as above which is: $ echo ...
13
votes
6answers
1k views

Only print output after finding pattern

There's a script (let's call it echoer) that prints to screen a bunch of information. I'd like to be able to only see lines after a pattern is found. I imagine the usage of a solution to look ...
0
votes
2answers
375 views

Linux ECHO output of a ECHO variable [duplicate]

I have a variable (var) which return value as VAR1 ($var has the value VAR1). There is an input file which has VAR1 defined (VAR1=ABCDEF) How can I use echo to get the value ABCDEF using $var?? I ...
1
vote
1answer
181 views

Bash: child process and pipelining

The purpose of my script is to count how many lines there are in a file. I know I could use wc for example but the purpose of this exercise is to understand processes and pipelines in Linux. The ...
0
votes
2answers
73 views

Script runs command fine, but fails when trying to save output to variable

I have a shell script with the following contents. I call it with ./script.sh. Echo successfully runs, but not when I try to save its output to a variable. The same is true for all commands I've ...
2
votes
1answer
150 views

Why does echo “a” | wc -m return 2? [duplicate]

Why does echo "a" | wc -m echo 2? Other variations in which I try to reduce the number of spaces yield the same result.