[kwlug-disc] BASH scripting - dpkg or variable issue?

Charles M chaslinux at gmail.com
Tue Jun 6 08:55:33 EDT 2023


Thanks everyone, this sent me down the rabbit hole where I found this
(tldp.org - it's been ages,  but still relevant):
https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

I ended up declaring the constant closer to the code, and simplifying
the contents, and now the script works. I saw an explanation of why it
shouldn't work, apparently (Korn Shell) ksh is better for what I was
trying to do. Shopt and lastpipe were mentioned as a workaround for
BASH, but simplifying the command the constant contained worked better
and made for simpler code.

The code now looks like this:

apt-get download shim.signed
SHIMFILE=$(ls shim-signed*)
echo $SHIMFILE
dpkg -x $SHIMFILE shim

The echo statement is just there to confirm the variable works.
Instead of SHIMFILE=$(ls | grep "shim.signed") at the top. Note:
apt-get download shim.signed does download a file with a hyphen
between shim-signed, not a period, thus the ls shim-signed* and not ls
shim.signed*.

Thanks everyone. Keep it simple I suppose.

On Mon, 5 Jun 2023 at 18:23, Khalid Baheyeldin <kb at 2bits.com> wrote:
>
> Another thing you can do is: do the echo from
> within the script, not after it finished, to see if
> it is set to the value you want from ls/grep.
> _______________________________________________
> kwlug-disc mailing list
> To unsubscribe, send an email to kwlug-disc-leave at kwlug.org
> with the subject "unsubscribe", or email
> kwlug-disc-owner at kwlug.org to contact a human being.



-- 
Charles
Mastodon: @chaslinux at techhub.social



More information about the kwlug-disc mailing list