Strange lspci -s "expression too long" issues

I am trying to do this:

SOCKET=$(lspci | grep 'Network' | awk '{print $1}')

lspci -vk -s $SOCKET

or this:

alias wificard="lspci -vk -s $(lspci | grep 'Network' | awk '{print $1}')"

or this

get_network_pci() {
    lspci -vk -s $(lspci | grep 'Network' | awk '{print $1}')
}

get_network_pci

These all work when executing them after another.

I can even run them in bash and fish without issues.

But always when trying to source it, be it with a script or with an alias, I get

~ ❯❯❯ wificard
lspci: -s: Expression too long
lspci: -s: Expression too long

Use this for script debugging:

sh -x -v /path/to/script
2 Likes
#!/bin/bash

SOCKET=$(lspci | grep 'Network' | awk '{print $1}')
++ lspci
++ awk '{print $1}'
++ grep Network
+ SOCKET=30:00.0

lspci -vk -s $SOCKET
+ lspci -vk -s 30:00.0
30:00.0 Network controller: Intel Corporation Wi-Fi 6 AX200 (rev 1a)
        Subsystem: Intel Corporation Wi-Fi 6 AX200NGW
        Flags: bus master, fast devsel, latency 0, IRQ 18, IOMMU group 18
        Memory at 80700000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: <access denied>
        Kernel driver in use: iwlwifi
        Kernel modules: iwlwifi

Works fine here too.

You can debug sourced code with logging enabled in the beginning of the script:

exec &>> /path/to/log

Then reproduce the issue and check the log.


Also make sure your code supports cases when grep returns empty or multiple results.

1 Like

Depending on what you’re trying to do you can also use:
lspci | grep -i -E 'thing you'd like to look for' | cut -b1-7 | xargs -i lspci -vnnks {}

2 Likes

You need to quote the use of $ in both cases.

Edit: otherwise the alias will run the code in $(...) when you define the alias not when it is typed.

2 Likes