Bug 27465 - ucr get sollte im return value anzeigen, ob eine Variable existiert
ucr get sollte im return value anzeigen, ob eine Variable existiert
Status: RESOLVED WONTFIX
Product: UCS
Classification: Unclassified
Component: UCR
UCS 4.1
All Linux
: P5 enhancement (vote)
: ---
Assigned To: UCS maintainers
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-06 13:40 CEST by Jürgen Kahrs
Modified: 2019-01-03 07:21 CET (History)
3 users (show)

See Also:
What kind of report is it?: Development Internal
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jürgen Kahrs univentionstaff 2012-06-06 13:40:45 CEST
Ich habe aus dem ucr eine Variable ausgelesen, die gar nicht gesetzt war. 

  ucr unset dns/fakeroot
  ucr get dns/fakeroot ; echo $?
  0

Hier wird der Leerstring auf stdout geliefert und ein return value von 0. Besser wäre es, einen anderen return value zu liefern, damit dieser Fall leichter auswertbar wird.

Streng genommen kann man ungesetzte Variable durchaus auch jetzt schon erkennen, nämlich so:

  ucr search dns/fakeroot
  dns/fakeroot: <empty>

Aber das ist zu umständlich und niemand macht das so. Deshalb wäre die Lösung mit dem return value wohl die praktisch sinnvollste.
Comment 1 Arvid Requate univentionstaff 2012-06-06 14:41:28 CEST
Workaround mit einer Kombination aus :? und ? Variablen-Quantoren in der Shell:

#!/bin/bash
eval "$(ucr shell)"

if (: ${dns_fakeroot:?unset_or_empty};) 2>/dev/null; then
    echo ok                        
elif (: ${dns_fakeroot?unset};) 2>/dev/null; then
    echo empty
else
    echo unset
fi
Comment 2 Philipp Hahn univentionstaff 2012-06-06 15:09:11 CEST
(In reply to comment #1)
> Workaround mit einer Kombination aus :? und ? Variablen-Quantoren in der Shell:

Das folgende Skript enthält einen subtilen Bug.

> #!/bin/bash

unset dns_fakeroot

> eval "$(ucr shell)"
> 
> if (: ${dns_fakeroot:?unset_or_empty};) 2>/dev/null; then
>     echo ok                        
> elif (: ${dns_fakeroot?unset};) 2>/dev/null; then
>     echo empty
> else
>     echo unset
> fi

ansonsten liefert "dns_fakeroot=foo ./script" das falsche Ergebnis: In UCR ist die Variable zwar nicht gesetzt, aber im Shell-Environment ist sie bereits durch den Vater-Prozeß gesetzt.

Wieder ein Beweis dafür, das "jedes gute Shell-Skript mit #!/usr/bin/perl" anfängt. (Zitat von einem (Ex-)Kollegen)
Comment 3 Arvid Requate univentionstaff 2012-06-06 16:28:52 CEST
Schöner wäre in der Tat die von Jürgen vorgeschlagene Anpassung des Returncodes.

..Freuden der Abbildung ternärer Logik ("Wert","",None) auf ein vorherrschend binäres Denken..
Comment 4 Stefan Gohmann univentionstaff 2019-01-03 07:21:32 CET
This issue has been filled against UCS 4.1. The maintenance with bug and security fixes for UCS 4.1 has ended on 5st of April 2018.

Customers still on UCS 4.1 are encouraged to update to UCS 4.3. Please contact
your partner or Univention for any questions.

If this issue still occurs in newer UCS versions, please use "Clone this bug" or simply reopen the issue. In this case please provide detailed information on how this issue is affecting you.