Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Size of Variable reporting inaccurate? #7

Open
MartineauUK opened this issue Jun 29, 2019 · 3 comments
Open

Size of Variable reporting inaccurate? #7

MartineauUK opened this issue Jun 29, 2019 · 3 comments

Comments

@MartineauUK
Copy link

MartineauUK commented Jun 29, 2019

Minor quibble for a variable of length 2999

'wc -m' or 'wc -c' appears to incorrectly report the NVRAM variable?

e.g.
echo $(nvram get jffs2_on)
1
Now print the size using your method
echo $(nvram get jffs2_on | wc -m)
2

@Xentrk
Copy link
Owner

Xentrk commented Jun 30, 2019

Thank you for the feedback. Looks like wc is counting the return or extra line? I updated the code to account for the extra character.

word_count=$(nvram get dhcp_staticlist | wc -m) # wc appears to count line return or extra line? word_count=$((word_count - 1))

I'll do more searching online to see how others have resolved the issue.

@ColinTaylorUK
Copy link

ColinTaylorUK commented Jun 30, 2019

Yes it's just because the string returned by "nvram get" is terminated with a linefeed.

admin@RT-AC68U:/# nvram get jffs2_on
1

admin@RT-AC68U:/# nvram get jffs2_on | hd
00000000 31 0a |1.|

@MartineauUK
Copy link
Author

I now use the following (having been prompted by you to review my code to make it POSIX complaint and more efficient ;-)

`NVRAM_DATA=$(nvram get "$NVRAM_VAR")

NVRAM_DATA_SIZE=${#NVRAM_DATA}`

although previously I used the slower (i.e. calling an external utility)
NVRAM_DATA_SIZE=$(echo "$NVRAM_DATA" | awk '{print length()}')
which conveniently ignores the LF character!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants