Variable completely messes up echoed stringusing awk to make new file, results in issues using 1 specific...

How to assert on pagereference where the endpoint of pagereference is predefined

What is the word which sounds like "shtrass"?

How did Arya manage to disguise herself?

Field Length Validation for Desktop Application which has maximum 1000 characters

An 'if constexpr branch' does not get discarded inside lambda that is inside a template function

How to back up a running Linode server?

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

Map one pandas column using two dictionaries

How did Arya get back her dagger from Sansa?

How to get SEEK accessing converted ID via view

I caught several of my students plagiarizing. Could it be my fault as a teacher?

Feels like I am getting dragged into office politics

When and why did journal article titles become descriptive, rather than creatively allusive?

How to implement float hashing with approximate equality

Is it the same airport YUL and YMQ in Canada?

What are the spoon bit of a spoon and fork bit of a fork called?

Is balancing necessary on a full-wheel change?

Short story about people living in a different time streams

Conflicting terms and the definition of a «child»

If 1. e4 c6 is considered as a sound defense for black, why is 1. c3 so rare?

Copy line and insert it in a new position with sed or awk

How could a planet have most of its water in the atmosphere?

Hang 20lb projector screen on Hardieplank

What happened to Rhaegal?



Variable completely messes up echoed string


using awk to make new file, results in issues using 1 specific column, can't figure out what is wrongAppend variable string to itselfTake output field data string into variableBash perform variable expansion of stringCombining a variable value and string to form another variableprintf escape %q string vs variablecompare variable with string bashPrinting variable value prints string Shell scriptingDo not expand string inside variablePrepare arguments containing quoted string in variableSSH terminal messes multiline commands






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







6















I discovered this website called pwnedpasswords, where you can apparently check to see if your password's sha1 hash has been leaked somewhere. So I made a script to automate the process, here's my script:



#!/bin/bash

read -s -p "Input your password: " your_pw
echo
your_hash=$(printf "$your_pw"|sha1sum|tr '[:lower:]' '[:upper:]'|head -c40)
hash_head=$(printf "$your_hash"|head -c5)
hash_tail=$(printf "$your_hash"|tail -c35)

pwned_count=$(curl https://api.pwnedpasswords.com/range/${hash_head} 2> /dev/null|grep "${hash_tail}"|awk -F ':' '{print $2}')
echo "Your password has been pwned ${your_pw} times"
echo "Your password has been pwned ${pwned_count} times"


And I used as a test password 1, and this is the output:



[me@my_compuuter aaa8]$ ./was_your_password_pwned.sh
Input your password:
Your password has been pwned 1 times
timesassword has been pwned 197972


Notice how when I echo "Your password has been pwned ${your_pw} times"
it gives me the correct format ($your_pw is just the password itself), but when I echo "Your password has been pwned ${pwned_count} times" it gives me this weird format where it takes the times from the end and somehow overlaps it in the beginning... I have no clue what's going on...



Can somebody figure it out?










share|improve this question

























  • Next time when you see something like this, pipe the output to od or cat -A.

    – Weijun Zhou
    Mar 18 at 3:32











  • Dupe unix.stackexchange.com/questions/312446/… and cross stackoverflow.com/questions/43837875/… (mine). bash can select characters without head or/and tail, and do case conversion without tr; awk can match like grep and do the CR removal; there are Qs on all of these.

    – dave_thompson_085
    Mar 18 at 4:49




















6















I discovered this website called pwnedpasswords, where you can apparently check to see if your password's sha1 hash has been leaked somewhere. So I made a script to automate the process, here's my script:



#!/bin/bash

read -s -p "Input your password: " your_pw
echo
your_hash=$(printf "$your_pw"|sha1sum|tr '[:lower:]' '[:upper:]'|head -c40)
hash_head=$(printf "$your_hash"|head -c5)
hash_tail=$(printf "$your_hash"|tail -c35)

pwned_count=$(curl https://api.pwnedpasswords.com/range/${hash_head} 2> /dev/null|grep "${hash_tail}"|awk -F ':' '{print $2}')
echo "Your password has been pwned ${your_pw} times"
echo "Your password has been pwned ${pwned_count} times"


And I used as a test password 1, and this is the output:



[me@my_compuuter aaa8]$ ./was_your_password_pwned.sh
Input your password:
Your password has been pwned 1 times
timesassword has been pwned 197972


Notice how when I echo "Your password has been pwned ${your_pw} times"
it gives me the correct format ($your_pw is just the password itself), but when I echo "Your password has been pwned ${pwned_count} times" it gives me this weird format where it takes the times from the end and somehow overlaps it in the beginning... I have no clue what's going on...



Can somebody figure it out?










share|improve this question

























  • Next time when you see something like this, pipe the output to od or cat -A.

    – Weijun Zhou
    Mar 18 at 3:32











  • Dupe unix.stackexchange.com/questions/312446/… and cross stackoverflow.com/questions/43837875/… (mine). bash can select characters without head or/and tail, and do case conversion without tr; awk can match like grep and do the CR removal; there are Qs on all of these.

    – dave_thompson_085
    Mar 18 at 4:49
















6












6








6








I discovered this website called pwnedpasswords, where you can apparently check to see if your password's sha1 hash has been leaked somewhere. So I made a script to automate the process, here's my script:



#!/bin/bash

read -s -p "Input your password: " your_pw
echo
your_hash=$(printf "$your_pw"|sha1sum|tr '[:lower:]' '[:upper:]'|head -c40)
hash_head=$(printf "$your_hash"|head -c5)
hash_tail=$(printf "$your_hash"|tail -c35)

pwned_count=$(curl https://api.pwnedpasswords.com/range/${hash_head} 2> /dev/null|grep "${hash_tail}"|awk -F ':' '{print $2}')
echo "Your password has been pwned ${your_pw} times"
echo "Your password has been pwned ${pwned_count} times"


And I used as a test password 1, and this is the output:



[me@my_compuuter aaa8]$ ./was_your_password_pwned.sh
Input your password:
Your password has been pwned 1 times
timesassword has been pwned 197972


Notice how when I echo "Your password has been pwned ${your_pw} times"
it gives me the correct format ($your_pw is just the password itself), but when I echo "Your password has been pwned ${pwned_count} times" it gives me this weird format where it takes the times from the end and somehow overlaps it in the beginning... I have no clue what's going on...



Can somebody figure it out?










share|improve this question
















I discovered this website called pwnedpasswords, where you can apparently check to see if your password's sha1 hash has been leaked somewhere. So I made a script to automate the process, here's my script:



#!/bin/bash

read -s -p "Input your password: " your_pw
echo
your_hash=$(printf "$your_pw"|sha1sum|tr '[:lower:]' '[:upper:]'|head -c40)
hash_head=$(printf "$your_hash"|head -c5)
hash_tail=$(printf "$your_hash"|tail -c35)

pwned_count=$(curl https://api.pwnedpasswords.com/range/${hash_head} 2> /dev/null|grep "${hash_tail}"|awk -F ':' '{print $2}')
echo "Your password has been pwned ${your_pw} times"
echo "Your password has been pwned ${pwned_count} times"


And I used as a test password 1, and this is the output:



[me@my_compuuter aaa8]$ ./was_your_password_pwned.sh
Input your password:
Your password has been pwned 1 times
timesassword has been pwned 197972


Notice how when I echo "Your password has been pwned ${your_pw} times"
it gives me the correct format ($your_pw is just the password itself), but when I echo "Your password has been pwned ${pwned_count} times" it gives me this weird format where it takes the times from the end and somehow overlaps it in the beginning... I have no clue what's going on...



Can somebody figure it out?







bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Rui F Ribeiro

42.5k1485146




42.5k1485146










asked Mar 17 at 19:07









user323587user323587

663




663













  • Next time when you see something like this, pipe the output to od or cat -A.

    – Weijun Zhou
    Mar 18 at 3:32











  • Dupe unix.stackexchange.com/questions/312446/… and cross stackoverflow.com/questions/43837875/… (mine). bash can select characters without head or/and tail, and do case conversion without tr; awk can match like grep and do the CR removal; there are Qs on all of these.

    – dave_thompson_085
    Mar 18 at 4:49





















  • Next time when you see something like this, pipe the output to od or cat -A.

    – Weijun Zhou
    Mar 18 at 3:32











  • Dupe unix.stackexchange.com/questions/312446/… and cross stackoverflow.com/questions/43837875/… (mine). bash can select characters without head or/and tail, and do case conversion without tr; awk can match like grep and do the CR removal; there are Qs on all of these.

    – dave_thompson_085
    Mar 18 at 4:49



















Next time when you see something like this, pipe the output to od or cat -A.

– Weijun Zhou
Mar 18 at 3:32





Next time when you see something like this, pipe the output to od or cat -A.

– Weijun Zhou
Mar 18 at 3:32













Dupe unix.stackexchange.com/questions/312446/… and cross stackoverflow.com/questions/43837875/… (mine). bash can select characters without head or/and tail, and do case conversion without tr; awk can match like grep and do the CR removal; there are Qs on all of these.

– dave_thompson_085
Mar 18 at 4:49







Dupe unix.stackexchange.com/questions/312446/… and cross stackoverflow.com/questions/43837875/… (mine). bash can select characters without head or/and tail, and do case conversion without tr; awk can match like grep and do the CR removal; there are Qs on all of these.

– dave_thompson_085
Mar 18 at 4:49












1 Answer
1






active

oldest

votes


















7














The list returned by that site has lines terminated by CR/LF. A CR (r) will move the caret/cursor to the beginning of the line:



printf 'good r times'
times





share|improve this answer
























  • Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

    – user323587
    Mar 17 at 19:23






  • 6





    @user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

    – ilkkachu
    Mar 17 at 19:31






  • 1





    Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

    – dave_thompson_085
    Mar 18 at 4:49












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506865%2fvariable-completely-messes-up-echoed-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














The list returned by that site has lines terminated by CR/LF. A CR (r) will move the caret/cursor to the beginning of the line:



printf 'good r times'
times





share|improve this answer
























  • Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

    – user323587
    Mar 17 at 19:23






  • 6





    @user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

    – ilkkachu
    Mar 17 at 19:31






  • 1





    Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

    – dave_thompson_085
    Mar 18 at 4:49
















7














The list returned by that site has lines terminated by CR/LF. A CR (r) will move the caret/cursor to the beginning of the line:



printf 'good r times'
times





share|improve this answer
























  • Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

    – user323587
    Mar 17 at 19:23






  • 6





    @user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

    – ilkkachu
    Mar 17 at 19:31






  • 1





    Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

    – dave_thompson_085
    Mar 18 at 4:49














7












7








7







The list returned by that site has lines terminated by CR/LF. A CR (r) will move the caret/cursor to the beginning of the line:



printf 'good r times'
times





share|improve this answer













The list returned by that site has lines terminated by CR/LF. A CR (r) will move the caret/cursor to the beginning of the line:



printf 'good r times'
times






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 17 at 19:20









Uncle BillyUncle Billy

1,0018




1,0018













  • Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

    – user323587
    Mar 17 at 19:23






  • 6





    @user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

    – ilkkachu
    Mar 17 at 19:31






  • 1





    Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

    – dave_thompson_085
    Mar 18 at 4:49



















  • Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

    – user323587
    Mar 17 at 19:23






  • 6





    @user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

    – ilkkachu
    Mar 17 at 19:31






  • 1





    Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

    – dave_thompson_085
    Mar 18 at 4:49

















Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

– user323587
Mar 17 at 19:23





Wow thanks! I just added |tr 'r' 'n' to the end of the pwned_count variable and now it works properly, thanks!

– user323587
Mar 17 at 19:23




6




6





@user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

– ilkkachu
Mar 17 at 19:31





@user323587, tr -d 'r' would be more common, it actually removes the carriage return. Changing it to a newline of course works in your case, too, since the command substitution removes all trailing newlines.

– ilkkachu
Mar 17 at 19:31




1




1





Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

– dave_thompson_085
Mar 18 at 4:49





Note use of CRLF line endings is common in Internet protocols, and in particular is required for content-type: text/plain in MIME (email, or news), see rfc2046 section 4.1.1. It not clear all MIME requirements should (or sometimes can) carry over to HTTP, but it is best to assume they do when there is no statement or clear evidence otherwise.

– dave_thompson_085
Mar 18 at 4:49


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506865%2fvariable-completely-messes-up-echoed-string%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...