Bash:代码输出中的换行符



这是我现在的代码:它似乎在哈希输出之前插入换行符,这是出于一些我无法弄清楚的奇怪原因。

hash=$(printf "$pswdOnen$pswdTwo"|grub-mkpasswd-pbkdf2 |awk '{print $7}')
myname=$(whoami)
echo "" > ./testoutput
printf "set superusers="$myname"" >> ./testoutput
printf "npassword_pbkdf2 $myname $hash" >> ./testoutput

下面是输出:

set superusers="thornegarvin"
password_pbkdf2 thornegarvin 
grub.pbkdf2.sha512.10000.03266E0763AA0C4E3D97C6DEA85DFBC4D34F97630C9FDE42B53E66D900341FF9F0988A7161C5A8B8EFA88AC33B1A06D459B6DA4D066EAB0EAC6B398DFF5FC3BB.614FE51D9ABB0D81695D080F9DF234FE05AB2955F485EC314917764D7E0DC3F3CC239F8C26DE36A8418E33CB89085312F0A9B6E283C407A4B8B3A2C1BC91C7F6

查看您的输出printf "$pswdOnen$pswdTwo"|grub-mkpasswd-pbkdf2您会发现输出了 3 行:

$ printf "testntest"|grub-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.A4ED2A115DD054DD002C6C70189AEE5DB2E737D4126BC15BD317EDD3A12FE9A1F1ED30AAEA6B223ABA19D5168867B57455491EB7B8E7B73FC0EAB617EC915B82.3C97F68C849082874FB72AB5DA50C1E33975894E1209D0E0FFAF23B784CC6E63E4D62778BC2917834E689C192DCE29D8E1620DFC4C2E97D447B89E3651AC829E

当您awk '{print $7}'时,您将获得两个空记录,它们只是换行符,然后是哈希值。而是执行以下操作:

printf "testntest"|grub-mkpasswd-pbkdf2 | tail -1 | awk '{print $7}'

printf "testntest"|grub-mkpasswd-pbkdf2 | awk '$1=="PBKDF2"{print $7}'

相关内容

  • 没有找到相关文章

最新更新