Linked Questions

30
votes
6answers
64k 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
0answers
1k views

echo -n option not working [duplicate]

I wanted to learn how the echo command works. I started with the following code. echo -n "What is your name -- " read i echo "Your name is $i" I do not understand why I still have a new trailing ...
0
votes
0answers
42 views

Need complete output into variable in bash [duplicate]

Following is the command which is in shell script. var="$(sshpass -p 'password' ssh -o "StrictHostKeyChecking=no" username@hostip <<-EOF command to run on remote host EOF )" when i echo $var, ...
0
votes
0answers
23 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: ...
397
votes
4answers
136k views

What does “--” (double-dash) mean? (also known as “bare double dash”)

I have seen -- used in the compgen command. For example: compgen -W "foo bar baz" -- b What is the meaning of the -- in there?
79
votes
18answers
199k 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 ...
53
votes
8answers
64k 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\...
19
votes
15answers
35k 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 ...
46
votes
6answers
138k 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 ...
35
votes
6answers
132k 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
31
votes
7answers
98k 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 ...
23
votes
8answers
2k views

Is piping, shifting, or parameter expansion more efficient?

I'm trying to find the most efficient way to iterate through certain values that are a consistent number of values away from each other in a space separated list of words(I don't want to use an array)....
32
votes
5answers
134k 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 ...
7
votes
5answers
2k views

How to list *.tar.gz, one filename per line?

I am trying to list every .tar.gz file, only using the following command: ls *.tar.gz -l ...It shows me the following list: -rw-rw-r-- 1 osm osm 949 Nov 27 16:17 file1.tar.gz -rw-rw-r-- 1 osm osm ...
21
votes
6answers
2k views

Is there another simple way to append line to end of file other than `>>`?

Recently I'm echoing short sentences to a tree_hole file. I was using echo 'something' >> tree_hole to do this job. But I was always worried of what if I mis-input of > instead of >>, ...

15 30 50 per page