2022 Developer Survey is open! Take survey.

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
0 answers
36 views

Why is shell/terminal printing extra new line. What can be done to prevent it?

root@kali-linux:~# echo -ne "hi" hi root@kali-linux:~# echo "hi" hi root@kali-linux:~# I am using bash shell, xfce + i3wm + stterm in kali. On previous version of kali, there ...
user avatar
  • 113
0 votes
2 answers
38 views

Trying to create a while loop to output content of one file to another

I am trying to create a while loop so that it takes content from one file and creates some content on another file. But what i noticed is that it is only creating the last line of the file instead of ...
user avatar
0 votes
0 answers
40 views

Weird behaviour of string concatenation in Bash [duplicate]

I have a problem with bash and string concatenation. Let's say that I have 2 variables: FILENAME=/rust-analyzer-x86_64-unknown-linux-gnu.gz URL=$(http --headers https://github.com/rust-lang/rust-...
user avatar
  • 111
13 votes
1 answer
1k views

Why is echo -e behaving weird in a Makefile?

I was writing a Makefile (on Ubuntu 20.04, if it's relevant) and noticed some interesting behavior with echo. Take this simple Makefile: test.txt: @echo -e 'hello\nworld' @echo -e '...
user avatar
0 votes
0 answers
19 views

Inquirer program answer questions by piping

Hi I have written this program with inquirer.js it has a list question and after that a text input. I want to answer both questions with piping. If I just keep the list question, I can easily use yes ...
user avatar
0 votes
0 answers
26 views

writing a private key from a variable to file

I have a scenario where I am exporting private key and writing it to a file. export CLI_KEY_FILE="-----BEGIN PRIVATE KEY----- 3MFPAZh1qa8XsLdlBBwRypZ8QxTzjdYe4trERoWoLMuaZWsAVRzTypCZG0/Hhfin ...
user avatar
  • 85
-2 votes
2 answers
41 views

Why does echo in Bash modify the content of a independent variable?

I have the following code (minimal example). #!/bin/bash ...
user avatar
  • 192
-2 votes
1 answer
33 views

How to handle "&" in Echo command [duplicate]

I required to Echo following information but I am getting error. echo Mumbai & Banglore But I am getting error as follows, 'Banglore' is not recognized as an internal or external command, ...
user avatar
  • 1
2 votes
1 answer
56 views

bash associative array where values are variables, print each value's variable name

I have the following associative array. var1="dog" var2="cat" var3="moose" declare -A asar01=( ["one"]="$var1" ["two"]="$var2" [&...
user avatar
  • 285
0 votes
1 answer
42 views

Source a script in Linux for all users logging in that echo some things

We have CENTOS 7.x Linux with bash shell. I need a some environment variables to be set and some messages involving these env vars to be echoed (a banner kind of thing, but dynamic because it's got ...
user avatar
0 votes
0 answers
93 views

Bash: echo command into tty

I've a service written in Python that can receive commands and does things, here is how it is built: print("\nWelcome!\n") for line in sys.stdin: cmd=line.rstrip() ...
user avatar
  • 701
10 votes
4 answers
2k views

How do I print the nth argument of a script, when n isn't known until runtime?

I am writing a shell script and I need to print the nth argument of the script. For example, suppose we have n=3 and our script is run with enough arguments. Now I need to print the nth argument, i.e. ...
user avatar
  • 189
0 votes
0 answers
12 views

How to expand regex from lines in a file similar to echo on command line? [duplicate]

I have a list of strings in a text file. The strings have regular expression ranges/lists in them. I want to be able to expand all the possibilities. It works if I select a string and paste it after ...
user avatar
  • 1
0 votes
1 answer
55 views

help using bind/unbind to power on/off USB drive

I'm trying to power on/off an USB drive using bind/unbind command following this post, can someone please point me to the right direction where to find tutorial/explanation on bind/unbind usb drive (...
user avatar
-3 votes
1 answer
43 views

Difference between two array printing methods in bash [duplicate]

I have an array declared in my script. NAME[0]=Deepak NAME[1]=Renuka NAME[2]=Joe NAME[3]=Alex NAME[4]=Amir echo "All Index: ${NAME[*]}" echo "All Index: ${NAME[@]}" There are two ...
user avatar
  • 5
0 votes
1 answer
44 views

Why echo is printing string variables before additional text that have been merged with it?

I have code in bash for making latex file and in this fragment I want to make a table in a loop: while IFS= read -r line; do if [[ "$line" == *"comment"* ]]; then ...
user avatar
0 votes
1 answer
54 views

Should echo be aliased to printf?

I'm not quite versed on the terminal, but the few things I've known and read lead me to believe that printf is much more powerful and confortable than echo but work for similar (if not same) purposes. ...
user avatar
0 votes
0 answers
35 views

Why doesn't creating file with echo work for remote directories in this script?

I aliased the following script: #!/usr/bin/bash if [[ -d "template.html" ]]; then : else cp -n /home/$(whoami)/CS/Software/Pollen/template.html . fi /usr/bin/echo "#lang pollen [...
user avatar
0 votes
2 answers
377 views

Write two variables in a two-column file (tab-separated)

Hello GNU/Linux newbie here. I want to write two variables in a two-columns tab-separated file. In my code, the variables are $sample_name and $file. I use the commands: touch to create the file and ...
user avatar
0 votes
2 answers
274 views

how to cycle thru a list in a file to search for missing files

I have script to open a text file which has a list of 1650 site locations. I am attempting to loop thru this list print two separate lists of files 1) which are found and 2) which are missing. The ...
user avatar
0 votes
0 answers
49 views

How can someone use a user-specified variable with a path?

I am trying to write a BASH script that can erase a disk. I am trying to use fdisk or perhaps shred in order to be able to erase a disk. I have it set up so that a user can specify the path to the ...
user avatar
  • 101
0 votes
0 answers
30 views

echo a variable differs between the unix distributions [duplicate]

i have a simple shell script that echoes variable in a file but i have issues getting it work the same way between the different distributions. The script #!/bin/sh res="=1B,\=AB=D2=DB=B5=A6e=FCj=...
user avatar
1 vote
2 answers
106 views

How to assign value using echo to a variable but don't display it in terminal [duplicate]

My bash script #!/bin/bash read -r -p "Enter the filenames: " -a arr for i in "${arr[@]}" do echo $i | sed 's/\(.*\)\..*/\1/' cp -v ~/Desktop/library/template.py "$i&...
user avatar
2 votes
1 answer
90 views

sed with here-string fails, but succeeds when echo output piped to sed

After updating sed to 4.4 version, sed doesn't replace spaces with commas in the output of find command given to it as here-string: sed --version sed (GNU sed) 4.4 ls -l /tmp/test/ total 0 -rw-r--r-- ...
user avatar
  • 287
0 votes
1 answer
289 views

how to use awk with echo in bash

If i run in bash script (similar to this one) to send content to a file: sudo ./bar.sh > foo content bar.sh: echo 'for pid in $(ps -ef | grep "smbd" | awk '{print $2}'); do kill -9 $pid &...
user avatar
  • 781
0 votes
2 answers
298 views

echo version or not to be

In the line of https://stackoverflow.com/questions/906590/echo-version-doesnt-works I need to know the version of echo $ type -a echo | cut -d " " -f 3- | xargs -d '\n' a shell builtin /usr/...
user avatar
  • 13
0 votes
0 answers
21 views

Bash array append - removes existing elements [duplicate]

I tried: $ a=("-f" "apple" "c") $ a+=("-e" "banana" "d") $ echo "${a[@]}" -f apple c -e banana d $ a=("-e" "apple&...
user avatar
  • 1,362
4 votes
2 answers
620 views

Using echo "" to create a new empty file isn't creating an empty file

I needed to create an empty file. So I used this: echo "" > file Then when I am performing a check in my program (if the file is empty) like this, if(file.content == '') do something ...
user avatar
-1 votes
2 answers
153 views

echo redirect appends a spaces

could someone help me? I am trying to create a lot of files, but when I try to write to it with echo it adds a space and single quotes, for example: ' (here is the space) file.tmp' ' file1.tmp' ' ...
user avatar
  • 11
20 votes
2 answers
2k views

How do you output a multi-line string that includes slashes and other special characters?

I would like to output this on completion of my bash script. /\_/\ ( o.o ) > ^ < I have tried the following but all return errors. echo /\\_/\\\n\( o.o \)\n > ^ < echo \/\\_\/\\\r\n( o....
user avatar
1 vote
0 answers
55 views

echo unescaping quotes causing formatting errors

I'm using bash with jq to parse some json objects, some of these objects have double quotes in their descriptions which are escaped with backslashes: { "title": "foo" "...
user avatar
-2 votes
3 answers
87 views

Why I can't move the content of a directory (including hidden files) to a file using only echo?

I have a directory named Musique and I want to have the list of files saved to nom.txt using ONLY echo. However I also want to copy the directory's hidden files and separate them from the "normal&...
user avatar
0 votes
1 answer
43 views

How to set a shell variable containing a single dash '-'?

How do I set a variable in Bash Zsh with a single dash (-)? None of these work: x=- x=\- x='-' EDIT: this seems to work fine in Bash, I was testing this with echo in Zsh which doesn't work.
user avatar
  • 400
0 votes
0 answers
46 views

echo each line from txt in in while

Hello im doing a simple script that i provide a list and the script response with the Location of the store. But i have problems in the response because i want this output echo "$stores ...
user avatar
  • 11
0 votes
0 answers
16 views

File loses linefeeds after reading from file [duplicate]

I have this bash script inputFile='input.txt' outputFile='output.txt' touch $outputFile contents=$(cat ${inputFile}) echo ${contents} >> ${outputFile} I read from the input file and output ...
user avatar
  • 4,204
0 votes
1 answer
296 views

Why is echo needed for IFS to take effect in zsh?

I am trying to read members of the PATH into an array using zsh 5.8. I am used to Bash, where the following normally works: IFS=: p=($PATH) However with zsh, this actually gives me an array with only ...
user avatar
  • 1,843
0 votes
0 answers
40 views

What does this wecho command do?

I found a script that makes a file list. The list looks like this /home/usr/example_directory /home/usr/example_directory/file1.txt /home/usr/example_directory/file2.txt /home/usr/different_directory /...
user avatar
  • 23
0 votes
1 answer
897 views

echo: write error: Operation not permitted issue

Hello i am trying to use the echo command to load firmware to the PRU on the Beaglebone black with the following command: root@beaglebone:~# echo 'am335x-pru1-fw' > /sys/class/remoteproc/...
user avatar
0 votes
1 answer
92 views

Why is this shell output cannot be written to a file? [duplicate]

I'm working on a linux pinephone script that would launch a touchpad emulator. In order to do so, I need to compare the output string of: ./TouchpadEmulator /dev/input/event2 /dev/input/event1 once I ...
user avatar
0 votes
1 answer
432 views

send udp broadcast via bash

I try to send a udp broadcast with 2 (FF 01) bytes over bash, but in my network sniffer I notice it's 3 bytes. FF 01 0A where does the line break come from and how can i prevent it? echo -e '\xFF\x01' ...
user avatar
  • 105
0 votes
1 answer
41 views

I want to output the result of a file using echo in Unix / Linux #QueueManager

A: runmqsc QueueManager < Input1 I want to output the result of A in a file. Input1 contains multiple codes that will be run in QueueManager. My command is: echo "runmqsc QueueManager < ...
user avatar
  • 1
0 votes
2 answers
77 views

Reassigning a variable using tr and getting rid of new line and carriage returns

I have a particular string loaded into a variable (v1). I want to define a new variable equal to this variable MINUS the new line and carriage returns so thus I need to delete the new line and ...
user avatar
2 votes
2 answers
972 views

Using echo or printf to print out new line and carriage returns as \n and \r

I am using echo to debug my shell script and would like to know how to use echo to also print out the new line \n and/or carriage return \r characters as well in the form \n and \r in order to inspect ...
user avatar
-1 votes
3 answers
176 views

Combine two pipe commands into a single command

I have theses two codes and i want to merge/combine them into a single one : rostopic echo /cmd_vel | grep -A 3 angular | grep -v x | grep -v y | cut -d : -f 2 rostopic echo /cmd_vel | grep -A 1 ...
user avatar
  • 15
-1 votes
1 answer
74 views

Issue detecting running processes from shell script

Script: #!/bin/bash kafka=`ps -ef | grep 'kafka' | grep -v grep | wc -l` echo $kafka if [ $kafka<3 ] then echo "Hi Support Team, Kafka is down on QA/Dev server $hostname .Please take ...
user avatar
0 votes
0 answers
53 views

problems with creating bash script with sed script

So, when i am creating file in my Docker manifesto with echo: RUN \ echo "#!/bin/bash\n\ mounted_tz=$(cat /etc/timezone)\n\ sed -i -r \"s~^(log_timezone\s*=\s*).*$~\1\'\$mounted_tz\'~\" ...
user avatar
  • 101
0 votes
1 answer
110 views

curl output for ISP different when using VPN

I'm doing a curl command to grab my ISP details. The problem is that the ISP details are different when connected to my company VPN. VPN disabled: isp=`curl -s ipinfo.io/org` echo: $isp Comcast Cable ...
user avatar
  • 47
-4 votes
2 answers
157 views

Creating an empty line

I'm currently trying to add an empty line in here, the example of the command that I have so far echo -e "my kernel version is $(uname -a) \nand the current date is $(date)" how do I change ...
user avatar
3 votes
3 answers
332 views

How to echo the literal "-n" [duplicate]

Is it possible to echo the two-character string -n using just the echo command built into the bash shell? I know I can do printf '%s\n' -n but was just wondering if the echo built-in is capable of ...
user avatar
  • 333
0 votes
1 answer
86 views

How do I make two echos output to a text file on separate lines [duplicate]

So I have a shell script math.sh which takes a number as an argument and echos one added to it and one subtracted from it: #!/bin/bash echo "Add: "$(($1 + 1)) echo "Subtract : "$((...
user avatar

1
2 3 4 5
10