Supressing an error message in bash script
Ray Parrish
crp at cmc.net
Sat Dec 12 02:40:14 UTC 2009
Hello,
I have the following code -
# This is a test of whether I can load an array line by line from a
command's output, instead of word by word.
function ArrayLoad {
PackageData=`"dpkg -p gedit"` 2> /dev/null
LoopCount=0
while [[ LoopCount < ${#PackageData} ]]; do
echo "$LoopCount - ${PackageData[$LoopCount]}"
(( LoopCount++ ))
done
}
Which outputs the following.-
ray at RaysComputer:~$ /home/ray/Bashscripts/TestScriptlet.sh
0 - Package: gedit
1 - Priority: optional
2 - Section: gnome
3 - Installed-Size: 2688
4 - Maintainer: Ubuntu Desktop Team <ubuntu-desktop at lists.ubuntu.com>
5 - Architecture: i386
6 - Version: 2.22.3-0ubuntu2
7 - Replaces: gedit-common (<< 2.16.2-3)
8 - Depends: gconf2 (>= 2.10.1-2), gedit-common (>= 2.22), gedit-common
(<< 2.23), iso-codes, libatk1.0-0 (>= 1.20.0), libattr1 (>= 2.4.4-1),
libc6 (>= 2.4), libcairo2 (>= 1.6.0), libenchant1c2a, libgconf2-4 (>=
2.13.5), libglade2-0 (>= 1:2.6.1), libglib2.0-0 (>= 2.16.0), libgnome2-0
(>= 2.17.3), libgnomeui-0 (>= 2.17.1), libgnomevfs2-0 (>= 1:2.17.90),
libgtk2.0-0 (>= 2.12.0), libgtksourceview2.0-0 (>= 2.2.0),
liblaunchpad-integration1 (>= 0.1.17), libpango1.0-0 (>= 1.20.5),
libx11-6, libxml2 (>= 2.6.27), python, python-glade2 (>= 2.9.7),
python-gobject (>= 2.11.5), python-gtk2 (>= 2.9.7),
python-gtksourceview2 (>= 2.2.0), python-support (>= 0.7.1), python2.5
(>= 2.5), scrollkeeper
9 - Recommends: libgnomevfs2-bin, python-gnome2, zenity
10 - Conflicts: gedit-common (<= 2.10.5-1)
11 - Size: 735948
12 - Description: official text editor of the GNOME desktop environment
13 - gedit is a text editor which supports most standard editor features,
14 - extending this basic functionality with other features not usually
15 - found in simple text editors. gedit is a graphical application which
16 - supports editing multiple text files in one window (known sometimes as
17 - tabs or MDI).
18 - .
19 - gedit fully supports international text through its use of the Unicode
20 - UTF-8 encoding in edited files. Its core feature set includes syntax
21 - highlighting of source code, auto indentation and printing and
print preview
22 - support.
23 - .
24 - gedit is also extensible through its plugin system, which currently
25 - includes support for spell checking, comparing files, viewing CVS
26 - ChangeLogs, and adjusting indentation levels.
27 - .
28 - Homepage: http://www.gnome.org/projects/gedit/
29 - Original-Maintainer: Debian GNOME Maintainers
<pkg-gnome-maintainers at lists.alioth.debian.org>
/home/ray/Bashscripts/TestScriptlet.sh: line 377: dpkg -p gedit: command
not found
ray at RaysComputer:~$
So it works the way I want it to, except for being able to suppress the
error message about 'command not found' at the end. I thought "2>
/dev/null" was the standard way to send an error message to oblivion,
but it's not working. Can someone tell me the right way to suppress the
error message?
I've also just tried -
PackageData=`"dpkg -p gedit 2> /dev/null"`
Which also outputs the error message.
Thanks, Ray Parrish
--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com
More information about the ubuntu-users
mailing list