Stack Exchange Network

Stack Exchange network consists of 174 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
vote
1answer
24 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
34 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 ...
0
votes
1answer
19 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
15 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
22 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
16 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
47 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
18 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
65 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
28 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
36 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
138 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
82 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
49 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
215 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
342 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
120 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-\...
4
votes
3answers
842 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
348 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
68 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
31 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
876 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
94 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
57 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
82 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
52 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
257 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
105 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
82 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
1k 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
48 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
531 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
311 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
258 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
64 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
33 views

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

First off I apologize for the title gore, I am struggling for a good way to summarize this issue. Anyway, I have been piping various things to functions using xargs and I am running into a weird ...
0
votes
1answer
144 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
84 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
55 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 ...
0
votes
2answers
4k views

using echo command with $ in shell script

Recently, i used echo command prefixing it with $. To my surprise what it resulted was an error. My command was something like this. # !/bin/bash $(echo 'a') The error was.. ./test1.sh: line 3: a: ...
0
votes
3answers
71 views

Escaping ; () in echo

how could i escaping ; or () or "" in echo ? I want to echo this command "LOAD DATA INPATH '$i' INTO TABLE transient.url_log_201803 partition (ds='$TGLS', periode='$WKTS');" but it says, syntax ...
0
votes
2answers
73 views

Printing variable doesn't print \ | / -

I am capturing Kafka startup script output into variable and while starting Kafka prints \ | / - to simulate spinning line. So when I do: res=`./confluent start kafka` echo $res The result is: ...
1
vote
2answers
365 views

I am trying to send stdout message to mailx — Red Hat

All, thanks for your help... This should be easy: My script prints this to stdout/terminal perfectly... its pretty in the script but not below... ???? : # Print to stdout echo "------- CAPACITY TEST ...
-1
votes
2answers
226 views

Backslashing does not work to send a bell via the echo command

The echo command doesn't want to interpret backlash escapes (with -e option attached). For example, I want it to ring a bell with: echo -e \a Nothing happens, except it prints: a or \a How to turn ...
0
votes
1answer
52 views

want to store date output in variable [duplicate]

i tried the below code to store the date output in variable. read -p 'date: ' mydate date_month= date -d "$mydate" +%b echo $date_month it is not printing the output. how to store the date output in ...
1
vote
1answer
201 views

Piping cat into wall (e.g. cat | wall)

Why does echo foo | wall work but cat | wall not work? In the latter case, I enter a couple lines into cat, and in theory they should pipe to wall; however, nothing happens.
2
votes
4answers
100 views

Ignore spacing between echo strings

I use echo to print two strings into a file in either of these two commands: echo -e "\n""x" >> ~/file echo -e "\n" "x" >> ~/file The first result is: x The second result is: x I ...
1
vote
1answer
25 views

variable name contains a variable inside it [duplicate]

I am trying to echo some values using a for loop. hwEventType.txt contains this : 11000 11002 11004 11006 13025 13026 Code : for event in $(cat /path/hwEventType.txt) do eval miny_"$event"_2001=`...