这是我现在的代码: 它似乎是在哈希输出之前插入换行符,这是因为我无法弄清楚的一些奇怪的原因。
hash=$(printf "$pswdOne\n$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
答案 0 :(得分:2)
看一下printf "$pswdOne\n$pswdTwo"|grub-mkpasswd-pbkdf2
的输出你会发现输出3行:
$ printf "test\ntest"|grub-mkpasswd-pbkdf2
Enter password:
Reenter password:
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.A4ED2A115DD054DD002C6C70189AEE5DB2E737D4126BC15BD317EDD3A12FE9A1F1ED30AAEA6B223ABA19D5168867B57455491EB7B8E7B73FC0EAB617EC915B82.3C97F68C849082874FB72AB5DA50C1E33975894E1209D0E0FFAF23B784CC6E63E4D62778BC2917834E689C192DCE29D8E1620DFC4C2E97D447B89E3651AC829E
当你awk '{print $7}'
时,你会得到两个空记录,它们只是换行符,然后是你的哈希值。而是做类似的事情:
printf "test\ntest"|grub-mkpasswd-pbkdf2 | tail -1 | awk '{print $7}'
或
printf "test\ntest"|grub-mkpasswd-pbkdf2 | awk '$1=="PBKDF2"{print $7}'