Use of && & || in Bash scripts (was: Using Ubuntu absolves the user of personal responsibility (no I'm guilty) and can you help me with my problem?)
Alexander Skwar
listen at alexander.skwar.name
Fri Aug 4 06:08:32 UTC 2006
· José Paulo Matafome Oleiro <matafomeoleiro at gmail.com>:
> $ sudo mount -o loop -t iso9660 /isofile /mountpoint && sudo apt-get
> install package_name && sudo mount -o loop -t
> iso9660 /isofile /mountpoint
> (this can mount the iso file at the end of the process again, should it
> work, or I need to replace && with || I don't know maybe you can help me
> with this out
&& means "do, if successful"
|| means "do, if not successful"
Thus your command line means:
mount isofile
if that's successful, do apt-get
if that (ie. apt-get) is successful, do mount isofile
&& and || are short forms for "if". Your command could also be written
as:
if sudo mount -o loop -t iso9660 /isofile /mountpoint; then
if sudo apt-get install package_name; then
sudo mount -o loop -t iso9660 /isofile /mountpoint
fi
fi
IMO, that's easier to understand.
The "BASH Programming HowTo" might be of interest. Google for it,
"you moron" ;)
Alexander Skwar
--
Unsere Handlungen sind nicht so lasterhaft wie unsere Absichten.
-- Luc de Clapiers Vauvenargues (Reflexionen und Maximen)
More information about the ubuntu-users
mailing list