2016-10-10 2 views
0

Ich versuche, einen Befehl basierend auf der Ausgabe eines anderen Skripts auszuführen. Sprich:Ausführen von Befehlen basierend auf der angegebenen Ausgabe

if [ -f /etc/debian_version]; then 
    DIST="Debian `cat /etc/debian_version`" 
fi 

OSDIST="$DIST" 

# here comes the part where I'm confused 

if [ $DIST = Debian 7.x (or if we're being specific here, say 7.9 for example) ]; then 
    execute_some_command 
elif [ $DIST = Debian 8.x (or if we're being specific here, say 8.1 for example) ]; then 
    execute_some_other_command 
fi 

Wie so etwas in SH zu codieren? Ich bin mir nicht sicher, welcher Parameter oder welche Option dafür verwendet wird. Vielen Dank!

+2

Eine Option ist "Fall" $ DIST "in (Debian 7. *): Do 7.x Zeug ;; (Debian 8. *): 8.x stuff ;; (*) : Welche Version;; esac'. –

Antwort

0

können Sie auch so etwas versuchen;

case `cat /etc/debian_version` in 

7.7*) echo "VERSION=7.7"; 
    execute_some_command; 
    ;; 

7*) echo "VERSION=7"; 
    execute_some_command; 
    ;; 

8*) echo "VERSION=8"; 
    execute_some_command; 
    ;; 

*) echo "VERSION=NONE"; 
    execute_some_command; 
    ;; 

esac 
Verwandte Themen