All Questions
36 questions
2
votes
1
answer
165
views
Print Variable containing backslashes
I have something like this:
A=$(curl https://mysite.com)
and the curl request returns the string \"Hello World\".
When I now want to print A to the console using one of:
echo "$A"
...
0
votes
1
answer
165
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 |...
0
votes
0
answers
35
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 ...
1
vote
1
answer
208
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: ...
3
votes
2
answers
2k
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
│ ├─...
0
votes
0
answers
525
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 ...
0
votes
2
answers
377
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. ...
2
votes
2
answers
2k
views
/bin/sh evaluates string while Bash does not
When running the script below, I get two different outputs, depending on whether or not the shell used is sh or bash:
regex(){
echo 's/\(.* \)\(!\{0,1\}\)has(/\1\2MOCK_has(/g'
}
replace_builtins(...
0
votes
1
answer
618
views
write to file with echo/printf [duplicate]
How to write the following to a file
printf "*\n!.gitignore\n" > $datadir/.gitignore
-bash: !.gitignore\n: event not found
3
votes
1
answer
1k
views
Why echo after printf is not displaying in a new line?
I have a code which will use printf and then echo command. As per my understanding echo will by default come in new line, but not happening when it is used after printf. Below is the code:
#!/bin/...
0
votes
1
answer
2k
views
Multiline Variable add a Tab before each Newline
The Following snippet uses a custom function HexNewLine which basically converts the hexdump and breaks at the character 0x0a
$ echo -e "\t{
> "dependencies": {
> "prettier": {
> ...
1
vote
4
answers
121
views
Generate tex file containing all filenames in a directory
I have a folder containing 95 tex files. I need to create a tex file all.tex that contains the following code:
\documentclass[10pt]{article}
\begin{document}
\input{file1.tex}
\input{file2.tex}
...
\...
1
vote
1
answer
654
views
How to print output to look like stairs?
My code is this in my shell script file:
for i in {0..3}
do
COLOR_Value="\033[1;3"$i"m \t Hello World"
echo -e $COLOR_Value
done
The output is this: (Each Hello World changes color as it ...
0
votes
4
answers
575
views
How to print the exact result of a command to a file
Context
I have a file my-cmd:
echo '<some data...>\\<some other data...>'
Basically, I want to redirect the output of this command to a text file:
./my-cmd > file.txt
Question
My ...
1
vote
1
answer
1k
views
how to print hyphen in double quotes along with other strings
cat inv_summary_1.txt | while read -r aLine
do
F1=`echo "$aLine" | cut -d "," -f1`
F2=`echo "$aLine" | cut -d "," -f2`
echo " 0 RUN_ID STR [0] \"${F2}\" "
done
191245204696,REG-...