PixL Posted September 16, 2018 Share Posted September 16, 2018 I have this bash script which functions but I am confused as my output appears as below with the stdout directly BEFORE my next bash prompt. What formatting do I need to change to fix this? #!/bin/bash function hex2string () { I=0 while [ $I -lt ${#1} ]; do echo -en "\x"${1:$I:2} let "I += 2" done } read -p 'Hexstring: ' varname hex2string "$varname" me@unknown ~ $ ./hex2ascii Hexstring: 4e4554474541523437 NETGEAR47me@unknown ~ $ Quote Link to comment Share on other sites More sharing options...
Foxtrot Posted September 16, 2018 Share Posted September 16, 2018 You use the '-n' flag in your echo to keep all the characters on one line during your loop. This means the last character to be decoded does not contain the newline character, either. You should print a newline after the loop has finished inside of the function with a simple 'echo'. Quote -n do not output the trailing newline https://linux.die.net/man/1/echo Quote Link to comment Share on other sites More sharing options...
PixL Posted September 18, 2018 Author Share Posted September 18, 2018 Thanks guys, I fixed it in the end and added a few extra bits... it takes a .16800 pmkid file and prints out the ssid of each separate pmkid. #!/bin/bash function hex2string () { I=0 while [ $I -lt ${#1} ]; do echo -en "\x"${1:$I:2} let "I += 2" done } read -p 'Enter PMKID filename: ' filename while read -r pmkid; do ssid="${pmkid:59:500}" hex2string "$ssid" echo echo "$pmkid" done < $filename Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.