ubuntu-manual team mailing list archive
-
ubuntu-manual team
-
Mailing list archive
-
Message #04290
Re: Improvements to install-pkgs.sh script
-
To:
Kevin Godby <godbyk@xxxxxxxxx>
-
From:
Jonathan Marsden <jmarsden@xxxxxxxxxxx>
-
Date:
Sun, 16 Jun 2013 07:15:07 -0700
-
Cc:
Manual mailing list <ubuntu-manual@xxxxxxxxxxxxxxxxxxx>
-
In-reply-to:
<CABk3zN699xkkSXEMgom-=DVxQk9SG5oMK-_u4Dgskjwy2XdT=g@mail.gmail.com>
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130330 Thunderbird/17.0.5
On 06/15/2013 09:59 PM, Kevin Godby wrote:
>> * Use set -e to exit when an error occurs.
> Does this interfere with the "try_this_command || handle_the_error"
> parts of the script?
No, only if a whole command line fails will it take effect. I did have
to modify some places where the script did something like
echo "$PKG" |grep -q ","
EXIT_STATUS=$?
if [ $EXIT_STATUS -eq 0 ]; then
because the grep in first of these lines would fail "on purpose"
sometimes, causing the script to exit. So I turned this into the
(shorter, easier to read, and slightly more efficient, IMO)
if [[ "$PKG" =~ "," ]]; then
instead, in two or three places. man bash says:
-e Exit immediately if a pipeline (which may consist of a
single simple command), a subshell command enclosed in
parentheses, or one of the commands executed as part of a
command list enclosed by braces (see SHELL GRAMMAR above)
exits with a non-zero status. The shell does not exit if
the command that fails is part of the command list
immediately following a while or until keyword, part of the
test following the if or elif reserved words, part of any
command executed in a && or ⎪⎪ list except the command
following the final && or ⎪⎪, any command in a pipeline
but the last, or if the command's return value is being
inverted with !.
>> * Sort and remove duplicates from package list.
> That's fine, though it's unnecessary as apt-get will take care of
> that for us.
True, but since I wanted to display it, it helps readability a lot :) :)
>> * Display package list before downloading and installing packages.
> Good idea. I haven't looked at your script code yet, but you could
> just allow the output from apt-get to be displayed on the screen so
> the user can see the download/install progress, too.
I thought about doing that, but you had apparently deliberately hidden
that output, so I decided there must be a reason for that choice... I
didn't want to trample on your design choices :)
Jonathan
References