Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
1answer
59 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 ...
0
votes
3answers
498 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
22 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
38 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
37 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
31 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 #...
3
votes
1answer
54 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
851 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
53 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
44 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
798 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
54 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
53 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
39 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
57 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.
0
votes
1answer
73 views

echo, pipe and command substitution

I want to substitute an echo command followed with | (pipe). For example, $(echo "echo 'hello' | cat") returns 'hello' | cat I expect this to behave like echo 'hello' | cat which returns hello ...
0
votes
0answers
18 views

How to update display command result in one line? [duplicate]

I want to clear and update display text in loop without new line. I try the following code: echo -ne "some text\r" But it is not really update the line but just overwrite the line without clear the ...
1
vote
2answers
32 views

wrong echo command

I am having a little problem with my ubuntu16.04 terminal. I wanted to have access to a data-base through the use of the : echo source /Infos/bd/config11 >> .bashrc echo source /Infos/bd/...
0
votes
1answer
27 views

Printf format error for number

After some greping and seding I manage to get a value from a csv cell and assign it to a variable (DBR). Here come some odd findings echo $DBR echo "$DBR", printf "%f" $DBR output: 9.1 ,.1 : ...
3
votes
2answers
222 views

What does echo $? do? [duplicate]

In my terminal it printed out a seemingly random number 127. I think it is printing some variable's value and to check my suspicion, I defined a new variable v=4. Running echo $? again gave me 0 as ...
0
votes
0answers
34 views

Why are trailing line breaks stripped when used as an argument (for echo)? [duplicate]

When I run this… echo " fdsfsd dsfsdf " I really get the output of all these lines. However, if I use this output as an argument for echo again…: echo "$(echo " fdsfsd dsfsdf ")" …...
0
votes
0answers
50 views

Need complete output into variable in bash [duplicate]

Following is the command which is in shell script. var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF command to run on remote host EOF )" when i echo $var, ...
1
vote
1answer
41 views

Echo'ing into a file only works with root and not sudo [duplicate]

I have a directory /sys/class/leds/ with the file bananapro\:green\:usr/trigger that controls an (green) onboard led. The contents of this file just contains the modes for the led. As root, I can run ...
0
votes
0answers
26 views

Avoiding echo -e [duplicate]

I would like to store an HTTP request in a variable and then use it with OpenSSL I now have HTTP_REQUEST="HEAD / HTTP/1.1\\nHost: ${HOST_HEADER}\\nUser-Agent: check_ssl_cert/${VERSION}\\nConnection: ...
1
vote
1answer
112 views

Define variable using read from stdin of heredoc

I am trying to store Available and Total Memory into variables in a script file as follows, read -r Available Total <<EOT $(free -m | awk '/^Mem/{print $7; print $2;}') EOT $ echo $Total $ ...
0
votes
1answer
51 views

Output string to log file, then pipe to function as argument

So I am trying to echo a string out to a log file and also pass that echo'd string over to a function along with other arguments as well. I can't seem to figure out how to do it or find any answers on ...
2
votes
1answer
26 views

How can I build an env file (with $ characters) listing as-is from echo command?

I am trying to build a file invoked from a script that echoes what is in quotes to a file - only, the $ gets omitted. This is what I was trying to do: echo -e "export ORACLE_BASE=/oracle/APP/grid \n ...
0
votes
1answer
16 views

How do I avoid this unexpected behaviour when redirecting output from echo?

I wanted to add to my hosts file easily using a one line command, but I get an unexpected result. $ sudo sh -c 'echo -e "10.0.10.0\tserver.bananas.com\tserver" >> /etc/hosts' $ cat /etc/hosts -...
0
votes
1answer
25 views

Why does read from variable give blank new variable? [closed]

I am trying to get a folder name from a stored variable string. When I ran the following path="Folder%20Name/Dir/File" read -d "/" folder < <(echo ${path/\%20/ }) echo "$folder" I am getting a ...
0
votes
1answer
30 views

color of echo with commands

i have the following command: echo -n $i". "${!ip}" - " ;curl -X POST http://${!ip}:50333/api/v1/version; echo " " I want the output to be green so what i did was echo -n -e "\e[32m$i". "${!ip}" - "...
0
votes
2answers
50 views

An echo operation includes some piece of text it should not include

On a WSL Ubuntu 16.04 (Xenial) with composer I executed: echo 2 * 3 > 5 is a valid inequality It resulted in a file by the name of 5, with the content: 2 composer-setup.php 3 is a valid ...
1
vote
2answers
27 views

How to echo content into a series of new file generated by cat

I would like to write a loop to generate 22 R scripts with contents generated in echo. What went wrong in this loop that I could not get the 22 files with the corresponding content? I tested echo "i ...
0
votes
3answers
88 views

find log files recursively and print “INVALID” if no log found (bash)

I have ~750 log directories I need to search for the latest log file available: These are captured by the allLogs.txt file and each entry contains a wild card '*' so that ONLY the log with the latest ...
0
votes
3answers
97 views

Shell - Print values in a comma separated string

I have a txt file with some comma separated values. cat file.txt abc,def,ghi abc,ghi def,abc,ghi def,abc abc,def abc,def,ghi I want to print these values with while do read line from file separated ...
0
votes
1answer
46 views

outputting 2 positions from same file into script and then echo

I have a file which looks like this: Sender Bob IP 10.1.1.1 Sender Alex IP 10.1.1.2 Sender Jim IP 10.1.1.3 10 lines like this in same format. I need to echo Name and IP. While iterating through my ...
1
vote
2answers
732 views

How to get counts of the files present in remote directory using sftp command

I have a sftp server (Dbprd@101.102.130.23) .I am trying to connect to the below sftp server and search for the files which contains .txt in (/files/base/incomming) path and get the count of lines in ...
0
votes
5answers
92 views

echo line with var that contains few lines

i have a file called 'file1.txt' that contain for exemple: bibi.toto jaja.bubu vrtegbvtr.rvgtbtdtbvtd And i want to echo some text with the var content(that contain the file1.txt lines) like that: ...
1
vote
1answer
54 views

how does echo recognize, when it should output list of files or pure text?

I encountered this question in my test: Make echo output all directories that start with a vowel (a,e,i,o,u,e), end with a number and have at least 3 characters. I thought this would be fairly easy, ...
1
vote
1answer
764 views

Process JSON, containing new lines, with JQ and bash [closed]

I receive a JSON with a curl call similar to the following: output="$(curl -s "$api_url")" This output is in the JSON format and has to be processed by jq, it looks like the following: { "test":...
1
vote
2answers
914 views

echo list / array to xargs [duplicate]

Say I have a list/array: list=(a b c) how can I echo each element to xargs? Something like: for v in list; do echo v; done; | xargs is there a less verbose way?
-1
votes
4answers
207 views

How should I use quoting with echo in Puppet?

I'm trying to use echo inside a Puppet rule to add a line to .bashrc, but I can't seem to get the quoting right. '/usr/bin/echo -E PS1=\"[\t--------------------------------------------------------\n-\...
3
votes
3answers
1k views

Xargs to extract filename

I would like to find all the .html files in a folder and append [file](./file.html) to another file called index.md. I tried the following command: ls | awk "/\.html$/" | xargs -0 -I @@ -L 1 sh -c '...
0
votes
2answers
1k views

Ansible: return status of the last task

I'm using this command to have a return from tasks in ansible. To see if they are successful or not. This is a example of my code in a playbook: - name: Install JDK8 shell: cd /tmp/install/ &&...
2
votes
1answer
106 views

Shell command executed differently in a terminal and script

The following sequence of commands ch=`echo "b_d" | sed 's/_/\\\\\\\\_/'` echo $ch when executed in a terminal or via source give an output b\\_d When ran as a scipt sh script.sh where the ...
0
votes
1answer
35 views

Echo a line of code to a file end up incomplete

While executing a script in bash echo "export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '" >> /home/testusername/.bash_profile While I am reading the file is missing one character which is a "\" ...
-1
votes
1answer
2k views

Why does echo <<EOF … EOF not work [duplicate]

Just wondering if anyone can explain why this works: echo `cat <<EOF {"branch":"foo","value":"bar"} EOF` but this doesn't: echo <<EOF {"branch":"foo","value":"bar"} EOF (the second ...
0
votes
4answers
217 views

How to compare lines in a single file line by line and append the output to the same file

I have a file abc.csv that has the below contents. a6caa290d03ae75dd5f3bf9214f0b523;CO.jar,a6caa290d03ae75dd5f3bf9214f0b523;CO.jar, a1a5bf1547f50feea4120290343f89e4;Common.jar,...
1
vote
2answers
63 views

Add Two Spaces in a variable

I need to add two consecutive spaces to a variable. for e.g I want to write Feb 5 (with two spaces in-between) in a variable. I am using the following command but I get Feb 5 instead. I am using AIX....
2
votes
2answers
93 views

bash echo the command line executed at the command line itself (not in a script)

For documentation purposes, I mean to redirect to file stdout and stderr from a command I execute. For instance, I would run (my command is less trivial than the alias ll but it probably doesn't ...
0
votes
2answers
121 views

Why are spaces echoing as newlines?

I've got this JSON data that looks like this: [ { "loginId": "7638749", "customerprofileDetails": { "securityQuestions": [ "What is your favorite sports team?", "What ...