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
1 answer
51 views

How to read files of kind "-diary.txt-" using echo?

I have a file named "-diary.txt-", I need to get it's content. When trying to read it using echo < "-diary.txt-", it returns a blank string. I did some research, and came up ...
Nikita Re's user avatar
0 votes
1 answer
79 views

Why does this "-e" option for echo get written to a file (although not enclosed in double quotes)? [duplicate]

#!/usr/bin/env python3 from subprocess import run from sys import modules def main(): doas() def doas(): ch = input("Ready to proceed with setting up doas?[Y/n]?") if ch == 'y': ...
John Smith's user avatar
0 votes
1 answer
40 views

Flush output continuously with xargs

The function output the size of the downloaded file and the speed of transfer separated with newline. Example: 20 #<< data 3.0M #<< speed 25 1.2M Now, it goes like this: output_data_func |...
decipher's user avatar
  • 162
0 votes
0 answers
31 views

printf and echo -n Work Differently - Why? [duplicate]

echo -n my_function() { echo -n "$@" } my_function hello world I get my desired output: hello world printf my_function() { printf "$@" } my_function hello world I get only ...
Pixelbog's user avatar
  • 540
1 vote
1 answer
30 views

Concatenating string passed into a control sequence

I have this echo invocation that prints a blue bar in a Bash terminal: echo $'\e[48;2;0;0;255m \e[0m' I would like to pass some variables to it, something like (this doesn't work): ...
user73235's user avatar
0 votes
1 answer
85 views

Does the echo command create a swap file when it writes a line to a file?

I am currently working on a personal project, and I would like to simply record logs in the following way using the echo command. My question is if the echo command accesses the same file at the same ...
JongSun Park's user avatar
0 votes
2 answers
121 views

Why is echo "\*" the same as echo "\\*"

Title. echo "\*" has the exact same output as echo "\\*", \*. I am using GNU bash 5.2.15. I expected echo "\\*" to output \*, but I do not know why echo "\*" ...
Christopher Lee's user avatar
0 votes
1 answer
26 views

extract last part of filename using echo - having assigned variables using wildcards

I am trying to extract parts of a filename, where I want to extract everything after the first _ and I have found a working solution, see below file=22NGS71294_S191_R1_001.fastq.gz echo $file ...
ch_esr's user avatar
  • 3
1 vote
1 answer
28 views

watch -n1 $() does not run $() every interval

watch -n1 $() does not update $(). what is the workaround? here is my example: watch -n1 echo $(( $(date +%s -d "sun") - $( date +%s ) )) this results in Every 1.0s: echo 106602 ...
stacking and exchanging woohoo's user avatar
0 votes
1 answer
84 views

Why I can pipe echo into bc, but I can't do the same with printf?

I can pipe echo into bc. But I cannot do the same with "printf": it gives syntax error. ❯ echo "100-5" | bc 95 ❯ printf "%s" "100-5" | bc (standard_in) 1: ...
robertspierre's user avatar
0 votes
3 answers
124 views

What does echo $$ do? [duplicate]

I was messing around with echo and was trying stuff like echo ~. When I was trying to use $ to substitute environment variables I accidentally tried echo $$. Surprisingly instead of an empty line I ...
nded23959's user avatar
0 votes
1 answer
31 views

Some dump comes out when giving inputs to program by using a pipe in Linux

I'm now trying to do exploitation by using a race condition bug. However, a problem occurs; Values that I have never given to the process come out. Below is a description of the case. Scenario: An ...
toubva's user avatar
  • 1
0 votes
0 answers
56 views

echo incorrectly interpreting colors

I want my terminal prompt to change color depending on success of the previous command. Currently I achieve this with the following script: exitstatus() { if [[ $? == 0 ]]; then echo -e &...
Trashbin2019np's user avatar
10 votes
3 answers
1k views

Temporarily unset bash option -x

I like to use set -x in scripts to show what's going on, especially if the script is going to run in a CI/CD pipeline and I might need to debug some failure post-hoc. One annoyance with doing this is ...
Ken Williams's user avatar
0 votes
1 answer
97 views

What are the types of echo output (Opaque, Semi-Opaque, Clear text) [closed]

I have an assignment from my lecturer to Write a script that will show each of the 3 types of echo (opaque, semi-opaque, and cleartext) The issue is, I don't know what the types are. I have searched ...
caged_raven_wings's user avatar
0 votes
2 answers
28 views

Echo message when flag is detected

This works well at running Seamonkey only once per 24 hours. I would like to show a message if the flag is detected. I am not sure where to put that echo statement. #!/bin/bash # # Run this script ...
fixit7's user avatar
  • 133
0 votes
1 answer
25 views

Echo'ing the variable muliple times while reading the variable values from a file

I am trying to write a bash script which would read values from a file and echo out the values. But for what ever reason it is not working correctly. My first file is having the below values Alts Risk ...
ranjit abraham's user avatar
3 votes
2 answers
1k views

How can I write in multiple files at once using 'cat'?

This question is kind of related to my previous question. This is the output of tree: [xyz@localhost Semester1]$ tree . ├── Eng │   ├── credits │   ├── links │   └── notes ├── IT │   ├── credits │   ├─...
Random Person's user avatar
0 votes
4 answers
268 views

Read from file; and execute its content line by line; terminate at first error [closed]

I am reading the content of a file do.sh using the bash command line structure. I want to execute each line of this file, line by line, so that, later, I can add some text to the script which can ...
Amit Kr. Ratewal's user avatar
4 votes
2 answers
424 views

How to print a double quote in POSIX scripting?

So far, I've been using "\"" to print a double quote: $ x="abc def" $ echo "x=\"$x\"" x="abc def" However, it seems like that behavior is ...
finefoot's user avatar
  • 2,980
1 vote
0 answers
131 views

How to export a variable and log the details to the console at the same time?

How to export a variable and log the details at the same time? For example, how to do the following in a one liner? export myvar=$var1$var2$var3 echo $myvar
phanin's user avatar
  • 119
2 votes
2 answers
1k views

Fastest way to write bash variable to a file

I want to generate some big files for some experiment. This is my script. It creates a file then reads it to a variable and then tries to write it as many times defined in the loop in files: #! /usr/...
DEKKER's user avatar
  • 846
0 votes
1 answer
529 views

can 'cat' command be a pipe target?

I used to do bash programming long, long time ago but over a period of time I moved onto other programming languages. My work demands I look into a bash script and I found this piece of code which I ...
stirfries's user avatar
  • 103
1 vote
2 answers
278 views

zsh: alias or shell function to only echo its command line, including shell control characters

Using zsh, I'd like to create an alias or a shell function that operates as follows: I want this alias or shell function to echo its command line without honoring any shell control characters such as &...
HippoMan's user avatar
  • 535
3 votes
2 answers
563 views

file listing: difference between ls and echo *

on a lustre file system with thousands of file in directories, each time I type ls I get a large delay until files are listed. Same happens with other commands that need file listing. But if I type ...
xaratustra's user avatar
0 votes
1 answer
83 views

echo >>regular_file vs echo >>&fd: one closes, other does not

In my observation, echo to regular file echo >>regular_file opens the file, appends to it, and then closes the file. Whereas echo to an open file descriptor echo >>&fd* doesn't close ...
codepoet's user avatar
  • 566
1 vote
1 answer
317 views

Why is it recommended to use "printf -- <arguments>" instead of "echo <arguments>?" [duplicate]

In the Bash Pitfalls on "Greg's Wiki" I found the following quote: In fact, the echo command cannot be used with absolute safety here. If the variable contains -n for example, echo will ...
Sante Kyaku's user avatar
0 votes
1 answer
40 views

I am trying to understand what a particular echo statement does

I am trying to understand what the second echo statement does exactly (it's an existing script).. echo "Triggering report.. " curl -s -X POST "http://aaa.bbb" echo -e \ '\ ' I ...
Teddy's user avatar
  • 103
2 votes
1 answer
510 views

How to display echo messages from a systemd-timer script in journalctl?

I run via a systemd timer a shell script that starts some programs (they display some output) and uses echo to provide some feedback. root@srv ~ [127]# cat /etc/systemd/system/borg.timer [Unit] ...
WoJ's user avatar
  • 1,455
2 votes
3 answers
852 views

How to add echo write commands to sudoers

I would like to add a command that use echo to write to files into sudoers so that it can be run without a password. Typically the command would go like this: sudo sh -c 'echo 1 > /sys/devices/...
Cestarian's user avatar
  • 2,011
7 votes
2 answers
1k views

How to write binary values into a file in Bash instead of ASCII values

I am dealing with an embedded system which has some memory that is accessible by a file descriptor (I have no idea what am I saying, so please correct me if I am wrong). This memory is 32 kB and I ...
DEKKER's user avatar
  • 846
3 votes
3 answers
1k views

How to print to stdout after exec >/dev/null

In a script, I have a long list of commands that print to stdout. I want to hide all output. So instead of redirecting each command, I put exec >/dev/null at the beginning. What options do I have ...
finefoot's user avatar
  • 2,980
0 votes
0 answers
28 views

Why is my script misbehaving sometimes? [duplicate]

I have created a script that can split an audio file into smaller files via ffmpeg using timestamps, and another script which can take in timestamps & names in batches. My use for this script ...
Cestarian's user avatar
  • 2,011
2 votes
3 answers
2k views

Stuck at removing a trailing newline from a string variable

Sometimes simplest things take your time in shell scripting like crazy. Content='me \n you \n him \n' echo $Content > Names.txt When I open the Names.txt it has two empty lines at the end. I want ...
Saeed Neamati's user avatar
-1 votes
1 answer
650 views

Why is “echo $SHELL” not captured by remote SSH output?

When I capture the output of a remote SSH call using cat, whether in bash or in Python, things work as expected. E.g, this works just fine: import subprocess rc = subprocess.getoutput(“ssh user@host; ...
Scott Skiles's user avatar
0 votes
2 answers
444 views

How to correctly line break and concatenate a string in a bash script

I have a Bash script with a function to log messages with time and status, and I want to keep my script 80 column only: #!/bin/bash log_message() { echo "[$(date)]-[$1] : $2" >> log....
DEKKER's user avatar
  • 846
0 votes
0 answers
236 views

write terminal output to file while keeping new lines [duplicate]

when I call env to see the environment variables it shows nicely with new lines: $ env SHELL=/bin/sh EDITOR=vi PWD=/home/user ... but when I want to store this to a file the new lines get ...
DEKKER's user avatar
  • 846
0 votes
0 answers
462 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 ...
Machinexa's user avatar
  • 123
0 votes
2 answers
2k 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 ...
ranjit abraham's user avatar
0 votes
0 answers
46 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-...
hc0re's user avatar
  • 111
17 votes
1 answer
6k 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 '...
Dominick Pastore's user avatar
0 votes
0 answers
126 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 ...
Steve Moretz's user avatar
0 votes
0 answers
649 views

writing a private key from a variable to file [duplicate]

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 ...
Jenifer's user avatar
  • 85
-2 votes
2 answers
405 views

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

I have the following code (minimal example). #!/bin/bash ...
kaiya's user avatar
  • 222
-2 votes
1 answer
225 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, ...
Vips's user avatar
  • 1
2 votes
1 answer
1k 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" [&...
Dave's user avatar
  • 542
0 votes
1 answer
233 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 ...
vharihar's user avatar
0 votes
0 answers
1k 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() ...
TCB13's user avatar
  • 721
10 votes
4 answers
3k 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. ...
David's user avatar
  • 199
0 votes
1 answer
2k 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 (...
michaelbr's user avatar

1
2 3 4 5
11