Linked Questions

10 votes
1 answer
2k views

Contents of file.txt (no weirdness, text file as defined by POSIX) iguana gecko anole Sample script: #!/bin/sh string="$(cat file.txt)" printf '%s' "$string" Sample output: [coolguy@somemachine ~]...
Harold Fischer's user avatar
0 votes
2 answers
1k views

Why the shell structure $(...) removes the ending newline character? #!/bin/bash S='a b ' printf '%i [%s]\n' "${#S}" "$S" T=$(printf '%s' "$S") printf '%i [%s]\n' "...
Olivier Pirson's user avatar
0 votes
1 answer
258 views

So let's say we have this code: a=$(echo -e "a\n\n\n") echo "_${a}_" the output is: _a_ which is kind of a surprise to me. Any ideas why this is happening?
tturbox's user avatar
  • 125
0 votes
1 answer
148 views

var1=$(printf "\n\x0A\n") var2=$(printf "\na\nb\nc") Using Android Terminal, the output of echo -e "$var1" (same for echo and printf) iss nothing, not even the 3 new lines. But echo -e "$var2" or ...
neverMind9's user avatar
  • 1,720
1 vote
0 answers
55 views

When I run this… echo " fdsfsd dsfsdf " I really get the output of all these lines. However, if I use this output as an argument for echo again…: echo "$(echo " fdsfsd dsfsdf ")" …I do ...
rugk's user avatar
  • 3,656
134 votes
9 answers
245k views

When I do str="Hello World\n===========\n" I get the \n printed out too. How can I have newlines then?
Jiew Meng's user avatar
  • 2,533
69 votes
5 answers
125k views

I have a text file named links.txt which looks like this link1 link2 link3 I want to loop through this file line by line and perform an operation on every line. I know I can do this using while loop ...
user3138373's user avatar
  • 2,589
14 votes
6 answers
3k views

If I have a string with nonprintable characters, new lines, or tabs, is there a way I can use echo to print this string and show codes for these characters (e.g., \n for new line, \b for backspace)?
drs's user avatar
  • 5,641
16 votes
2 answers
4k views

The following code best describes the situation.  Why is the last line not outputting the trailing newline char?  Each line's output is shown in the comment.  I'm using GNU bash, version 4.1.5 ...
Peter.O's user avatar
  • 33.8k
3 votes
5 answers
4k views

I would like to write a program that reads from a text file and prints in Terminal the words of that file character by character every one second. For example, in a text file log.txt let's say I have ...
Zahi's user avatar
  • 297
3 votes
4 answers
6k views

When I want to replace, say Dot with Dot ##empty line## I do this: sed 's/Dot/Dot\ /g' Yes, a literal new line, this is the way it works on BSD sed. But, I can't do the same when the sed is inside ...
DisplayName's user avatar
3 votes
1 answer
3k views

Attempt 1 xargs -I '{}' -0 -n 1 myprogram --arg '{}' --other-options But that does not preserve zero bytes. Also the program may run multiple times. But instead of failing in case of zero byte ...
Vi.'s user avatar
  • 6,005
8 votes
2 answers
2k views

I'm customizing my zsh PROMPT and calling a function that may or may not echo a string based on the state of an environment variable: function my_info { [[ -n "$ENV_VAR"]] && echo "Some ...
dtk's user avatar
  • 203
1 vote
2 answers
4k views

page=`grep $x /var/www/vhosts/example.com/statistics/logs/access_log | awk '{print $7}'| sort |uniq -c |sort -nr` times=`$page | wc -l` I am trying to save output of grep in a variable as page. But ...
NecNecco's user avatar
  • 721
1 vote
1 answer
70 views

These 2 variables will have the same visible content x_sign1="aabbccdd_and_somthing_else" var1="...." [........] x_sign2=$(echo -n "${var1}${var2}${var3}" | shasum -a 256) echo $x_sign2 ...
Immani's user avatar
  • 11

15 30 50 per page