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.

0
votes
1answer
25 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
13 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
16 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
143 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
30 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
45 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
38 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
24 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
61 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
47 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
23 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
19 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
23 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
87 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
43 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
42 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
440 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
86 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
50 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
448 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
659 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
171 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
894 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
81 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
33 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
158 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
61 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
88 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
78 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 ...
2
votes
3answers
452 views

why piping pwd and echo does not work? [duplicate]

I'm new to unix. I typed this command in ubuntu terminal: pwd | echo I expected to see the output of pwd in terminal(/home/fatemeh/Documents/Code/test) but the output was just a single empty line. ...
0
votes
3answers
153 views

Echo Permission Denied (Trying to use echo instead of ls command in shell script)

I am trying to write a script and at some point i needed to list all the things in a directory and grep someting from that directory. I can't do it with ls. ls is not my guy to do it. So i tried to do ...
3
votes
1answer
31 views

appending a line to a file if absent

I'd like to add a series of commands to a Makefile that append config lines when they are not already present. I've done this in the past in a manner like so: grep -vq "keyword" /a/b/c.conf &&...
-3
votes
1answer
154 views

Printf appending fails

I Tried to run the following similar commands in CentOS (12.x): printf "\nhello" "$HOME"/.bashrc printf "\nhello" ${HOME}/.bashrc After execution I display the content of the .bashrc file and see ...
13
votes
4answers
2k views

Is it possible to print the content of the content of a variable with shell script? (indirect referencing)

Let's suppose I've declared the following variables: $ var='$test' $ test="my string" If I print their contents I see the following: $ echo $var $test $ echo $test my string I'd like to find a ...
-1
votes
1answer
56 views

What does command “echo run -d” do?

I was going through some scripts in my organisation, and I'm wondering what echo run -d does. Note: The script was used to execute a jar file with some arguments.
1
vote
2answers
689 views

How to append multiple lines before the last line using echo command

{ This is test1 this is test2 this is test3 } Now i want append multiple lines before the last line using echo command Anyone please help me!!!! My output is look like below { ...
1
vote
2answers
399 views

Compare two variables with a Shell script

I have a script that allows me to compare these variables: FT_NBR1=\'?"\"'\ FT_NBR2=rcrdmddd My question is how can I pass the FT_NBRs variables to the script to execute the comparison in the ...
1
vote
1answer
420 views

SSH remote - display echo on local terminal

The following is a part of my script where I want to echo some text to the local terminal if the condition fails in ssh. /usr/bin/sshpass -p $PASSWORD /usr/bin/ssh -t -o "StrictHostKeyChecking no" ...
0
votes
4answers
68 views

echo append onto existing row, continue on the row

How can I append the string :/etc/simmmerin/bin/ into a file filename using echo command onto an existing row. Can't get it working. echo ":/etc/simmerin/bin/" >> filename It just appends in ...
2
votes
2answers
42 views

Converting stdout to raw-data not accepting multiple words using xargs and piping

I am currently running the command: echo "hello world" | xargs curl http://localhost:8080/function/func_wordcount -d" which takes the stdout of echo "hello world" and then pipes it to func_wordcount ...
0
votes
1answer
178 views

Operation of ` with echo when trying to awk [duplicate]

How come echo `echo "foo"` works but echo `awk '{ print "foo" }'` doesn't?
11
votes
2answers
3k views

Is it dangerous to run echo without quotes?

I've seen couple of similar topics, but they are referring to not quoting variables, which I know could lead to unwanted results. I saw this code and was wondering would if it be possible to inject ...
-1
votes
2answers
98 views

How to give inputs to the .sh in command line [closed]

I have script abc.sh and it shows 4 options to user & 1 we need to choose. at first we give inputs as 1 -for the first option Now again it will show me 3 options and I have to choose as 1 -for ...
0
votes
2answers
59 views

Basic doubt in echo statement

I have just started learning unix and came across very basic doubt in command line arguments. Suppose if in my script i do: echo $@ #Now this prints all the command line arguments args=$@ #Args ...