For the following execution and result of sha256sum
~/HydroGuardFW/hw_1_5/Debug$ sha256sum debug_2.0.5.hex
34c977f0df3e90f9a4b36da3cd39fdccf3cd1123c563894b3a3378770a19fc6d debug_2.0.5.hex
The output will be in two parts, the sha256 and the echo of the file name of which the sha256 sum was calculated. How do you grab the first part part of the output, which is the sha256 into a variable so it can be placed into a file using bash script.
Syntax: Read file line by line on a Bash Unix & Linux shell The syntax is as follows for bash, ksh, zsh, and all other shells to read a file line by line: while read -r line; do COMMAND; done < input. file. The -r option passed to read command prevents backslash escapes from being interpreted.
You don't need store it in a variable. You can directly redirect it to the file as well.
sha256sum debug_2.0.5.hex | awk '{print $1}' > dsl
If you do need to store it in a variable for some other purpose then:
read -r shm_id rest <<<"$(sha256sum scr)"
echo $shm_id > dsl
or
shm_id=$(sha256sum scr | awk '{print $1}')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With