NerdFetch icon indicating copy to clipboard operation
NerdFetch copied to clipboard

NetBSD sh fails because of bash feature

Open polluks opened this issue 3 years ago • 4 comments

./nerdfetch: 16: Syntax error: Bad substitution

see https://stackoverflow.com/a/20323801/1430535

polluks avatar May 27 '22 12:05 polluks

It works somehow...

$ sh nerdfetch 
nerdfetch: 16: Syntax error: Bad substitution
$ csh nerdfetch 
Illegal variable name.
$ ksh nerdfetch 
?ffnen von //var/pkg/lib/rpm/packages.rpm fehlgeschlagen

nerdfetch[109]: sysctl: not found
expr: non-integer argument 'idk'
usage: expr expression

      ___     polluks@host 
     (.. \      Idk
     (<> |      8.2
    //  \ \     idk/idk MB (%)
   ( |  | /|           0 (rpm)
  _/\ __)/_)    19198 days, 40 mins
  \/-____\/     ██████████████████

polluks avatar Jul 25 '22 00:07 polluks

Hm... weird :smile: Unless you've kept your computer alive for over 52 years I don't think that uptime is correct... I'm really not familiar with how BSD shells work so I can't exactly pinpoint what's going wrong :/

ThatOneCalculator avatar Jul 25 '22 01:07 ThatOneCalculator

By the way I'm not root, it's a free account http://freeshell.org. At least /sbin/sysctl -n kern.boottime does work, sbin is not in my PATH.

polluks avatar Jul 25 '22 15:07 polluks

Please read https://stackoverflow.com/questions/13210880/replace-one-substring-for-another-string-in-shell-script carefully: "Note that this feature is not specified by POSIX — it's a Bash extension — so not all Unix shells implement it."

polluks avatar Jul 26 '22 13:07 polluks

Fixed in 7.1.0

ThatOneCalculator avatar Jan 11 '24 22:01 ThatOneCalculator

$ sh nerdfetch
nerdfetch: 17: Syntax error: Bad substitution
$ zsh nerdfetch
nerdfetch:131: command not found: sysctl
nerdfetch:185: command not found: sysctl
nerdfetch:185: bad math expression: operand expected at `/ 1024 / 1...'
$ bash nerdfetch
nerdfetch: Zeile 131: sysctl: Kommando nicht gefunden.
nerdfetch: Zeile 185: sysctl: Kommando nicht gefunden.
nerdfetch: Zeile 185: / 1024 / 1024: Syntaxfehler: Operator erwartet. (Fehlerverursachendes Zeichen ist "/ 1024 / 1024").
expr: syntax error
usage: expr expression

      ___     polluks@host 
     (.. \      Idk
     (<> |      9.3
    //  \ \   󰍛  / MiB (%)
   ( |  | /|  󰏔       476 (bin)
  _/\ __)/_)  󰅶  19734 days, 23 hours, 47 mins
  \/-____\/     ██████████████████

polluks avatar Jan 12 '24 23:01 polluks

Sorry, thought I fixed that

ThatOneCalculator avatar Jan 13 '24 00:01 ThatOneCalculator

Also, what OS and shell are you currently using? (the one linked to sh)

ThatOneCalculator avatar Jan 13 '24 00:01 ThatOneCalculator

@polluks Can you please try the latest Git version, assuming you're still on NetBSD?

ThatOneCalculator avatar Jan 13 '24 01:01 ThatOneCalculator

Well...

nerdfetch: Zeile 129: pkg_info: Kommando nicht gefunden.
sysctl: second level name 'stats' in 'vm.stats.vm.v_free_count' is invalid
sysctl: second level name 'stats' in 'vm.stats.vm.v_page_size' is invalid
nerdfetch: Zeile 215: *  / 1024 / 1024: Syntaxfehler: Operator erwartet. (Fehlerverursachendes Zeichen ist "*  / 1024 / 1024").
expr: syntax error
usage: expr expression

      ___     polluks@sdf 
     (.. \    󰉀  NetBSD 9.3
     (<> |      9.3
    //  \ \   󰍛  /0 MiB (%)
   ( |  | /|  󰏔  0 (pkg)
  _/\ __)/_)  󰅶  29 days,  2:55
  \/-____\/     ██████████████████

How about this fallback?

$ free
             total       used       free    buffers
Mem:      16274444   15094860    1179584    9102496
Swap:      2097148          0    2097148

polluks avatar Jan 13 '24 20:01 polluks

It'd probably be better practice to use sysctl, is there a significant difference between FreeBSD's version and NetBSD's?

ThatOneCalculator avatar Jan 13 '24 21:01 ThatOneCalculator

Also,

nerdfetch: Zeile 129: pkg_info: Kommando nicht gefunden.

Does your NetBSD install not have pkg_info? I thought that was standard for NetBSD...

ThatOneCalculator avatar Jan 13 '24 21:01 ThatOneCalculator

standard for root...

Am Sa., 13. Jan. 2024 um 22:31 Uhr schrieb Kainoa Kanter < @.***>:

Also,

nerdfetch: Zeile 129: pkg_info: Kommando nicht gefunden.

Does your NetBSD install not have pkg_info? I thought that was standard for NetBSD...

— Reply to this email directly, view it on GitHub https://github.com/ThatOneCalculator/NerdFetch/issues/39#issuecomment-1890773744, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABD5J5ISSRUWT26F4IL22GTYOL4KDAVCNFSM5XEC3OIKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBZGA3TOMZXGQ2A . You are receiving this because you were mentioned.Message ID: @.***>

polluks avatar Jan 14 '24 02:01 polluks

Wdym "standard for root"? How do you manage packages?

ThatOneCalculator avatar Jan 14 '24 03:01 ThatOneCalculator

I‘m a NetBSD user, I‘m unable to manage packages at all.

polluks avatar Jan 14 '24 11:01 polluks

But as a user, you can't even query installed packages?!

ThatOneCalculator avatar Jan 14 '24 15:01 ThatOneCalculator

Well, I have pkgconf and this

$ ls /usr/pkg/bin | which wc

2385    2385   23246

Am So., 14. Jan. 2024 um 16:55 Uhr schrieb Kainoa Kanter < @.***>:

But as a user, you can't even query installed packages?!

— Reply to this email directly, view it on GitHub https://github.com/ThatOneCalculator/NerdFetch/issues/39#issuecomment-1890989823, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABD5J5ID6ZP5LLLOMIVSDRTYOP5VRAVCNFSM5XEC3OIKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBZGA4TQOJYGIZQ . You are receiving this because you were mentioned.Message ID: @.***>

polluks avatar Jan 15 '24 19:01 polluks

By the way every fetch has this issue

$ ./afetch
pkg_info: not found
\\`-______,----__
 \\        __,---`_       USER polluks
  \\       `.____           OS NetBSD
   \\-______,----`-     KERNEL 9.3
    \\                  UPTIME 0h 0m
     \\                  SHELL zsh
      \\                  PKGS 0

polluks avatar Jan 16 '24 07:01 polluks

I think your setup might just be a bit to esoteric to globally support... I can try and pull something off but it might literally only benefit you 😆 not that I'm opposed

ThatOneCalculator avatar Jan 16 '24 08:01 ThatOneCalculator

Sorry for interrupting the talk but what shell are you using @polluks?

Also for memory (available/free), NetBSD doesn't have sysctl entry for this, there are separate module for it but not possible to call from a shell script. For now, you can use vmstat, (e.g. mem_free=$(($(vmstat | awk 'NR==3 {print $4}') / 1024)))

Everything else looks okay to me, except a few minor nitpicks image

rilysh avatar Jan 17 '24 17:01 rilysh

By the way every fetch has this issue

$ ./afetch
pkg_info: not found
\\`-______,----__
 \\        __,---`_       USER polluks
  \\       `.____           OS NetBSD
   \\-______,----`-     KERNEL 9.3
    \\                  UPTIME 0h 0m
     \\                  SHELL zsh
      \\                  PKGS 0

Do you manage packages using pkgsrc or binary packages using pkgin? pkgin and pkgsrc both are optional, but I'm not sure why your pkg_info is missing there (as the error suggests). Anyway, if pkg_info isn't there but pkgin is, then pkgin list | wc -l should fallback to.

rilysh avatar Jan 17 '24 17:01 rilysh

For now, you can use vmstat, (e.g. mem_free=$(($(vmstat | awk 'NR==3 {print $4}') / 1024)))

If you could PR that for NetBSD that'd be great. I know next to nothing about NetBSD, even my FreeBSD/OpenBSD skills are very rudimentary.

ThatOneCalculator avatar Jan 17 '24 17:01 ThatOneCalculator

I'm using zsh and have access to pkgconf and pkgdata. At least echo $(($(vmstat | awk 'NR==3 {print $4}') / 1024)) works.

polluks avatar Jan 18 '24 08:01 polluks

For now, you can use vmstat, (e.g. mem_free=$(($(vmstat | awk 'NR==3 {print $4}') / 1024)))

If you could PR that for NetBSD that'd be great. I know next to nothing about NetBSD, even my FreeBSD/OpenBSD skills are very rudimentary.

Here's one #48

rilysh avatar Jan 18 '24 09:01 rilysh

I'm using zsh and have access to pkgconf and pkgdata. At least echo $(($(vmstat | awk 'NR==3 {print $4}') / 1024)) works.

pkgconf isn't a "package" manager so isn't really relevant to this source. You've to use pkgin or pkg_info to query packages.

rilysh avatar Jan 18 '24 09:01 rilysh