Linked Questions
344 questions linked to/from Why is printf better than echo?
63
votes
6
answers
147k
views
Difference between printf and echo in bash [duplicate]
What is the difference between the printf function in bash and the echo function?
Specifically, running:
echo "blah" >/dev/udp/localhost/8125
did not send the "blah" command to the server ...
0
votes
1
answer
713
views
How to replace `\t` with a TAB character in a string, in a way that is independent of the shell? [duplicate]
I have a script that is going to be executed by sh and bash on Debian Linux.
When it is called by sh, the following echo command works perfectly, and replaces \t with 3 spaces. However, it fails when ...
0
votes
0
answers
60
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: ...
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=...
0
votes
0
answers
12
views
zsh command expansion applies esacping [duplicate]
I have a string S, for which I want to replace every b character with \\ (two forward slashes).
So this is what I have:
$ S="abc"
$ A=$(echo $S | sed 's/b/\\\\/')
In bash I get the expected ...
718
votes
5
answers
286k
views
What does "--" (double-dash) mean?
I have seen -- used in the compgen command.
For example:
compgen -W "foo bar baz" -- b
What is the meaning of the -- in there?
304
votes
12
answers
553k
views
How can I test if a variable is empty or contains only spaces?
The following bash syntax verifies if param isn't empty:
[[ ! -z $param ]]
For example:
param=""
[[ ! -z $param ]] && echo "I am not zero"
No output and its fine.
But when param is ...
122
votes
20
answers
310k
views
How to count the number of a specific character in each line?
I was wondering how to count the number of a specific character in each line by some text processing utilities?
For example, to count " in each line of the following text
"hello!"
Thank you!
The ...
80
votes
8
answers
116k
views
How to delete line with echo?
I know that I could delete the last three chars with:
echo -ne '\b\b\b'
But how can I delete a full line? I mean I don't want to use:
echo -ne '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\...
76
votes
9
answers
247k
views
Can sed replace new line characters?
Is there an issue with sed and new line character?
I have a file test.txt with the following contents
aaaaa
bbbbb
ccccc
ddddd
The following does not work:
sed -r -i 's/\n/,/g' test.txt
...
39
votes
15
answers
87k
views
'ls -1' : how to list filenames without extension
ls -1 lists my elements like so:
foo.png
bar.png
foobar.png
...
I want it listed without the .png like so:
foo
bar
foobar
...
(the dir only contains .png files)
Can somebody tell me how to use ...
72
votes
9
answers
267k
views
How to add new lines when using echo
Why does the following command not insert new lines in the generated file and what's the solution?
$ echo "Line 1\r\nLine2" >> readme.txt
$ cat readme.txt
Line 1\r\nLine2
76
votes
8
answers
169k
views
Bash: Assign output of pipe to a variable
I am trying to get the output of a pipe into a variable. I tried the following things:
echo foo | myvar=$(</dev/stdin)
echo foo | myvar=$(cat)
echo foo | myvar=$(tee)
But $myvar is empty.
I don’...
72
votes
6
answers
189k
views
Concatenating two variables with an underscore
I need to concatenate two variables to create a filename that has an underscore.
Lets call my variables $FILENAME and $EXTENSION where filename is read from a file.
FILENAME=Hello
EXTENSION=WORLD.txt
...
72
votes
5
answers
318k
views
Redirecting the content of a file to the command "echo"
I have a file named my_file.txt whose content is just the string Hello. How could I redirect its content to the command echo?
I know I have the commands less, cat, more... but I need to do it with ...