84 lines
2.2 KiB
TeX
Executable File
84 lines
2.2 KiB
TeX
Executable File
\section{Exec}
|
|
\begin{flushleft}
|
|
Mit dem Befehl {\ttfamily exec} kann man Befehle ausf"uhren, ohne eine neue Shell / Process zu starten.\\
|
|
|
|
\listBash
|
|
\begin{lstlisting}[captionpos=b, caption=Exec Example, label=lst:bash]
|
|
uws@tux>bash
|
|
uws@tux>pstree
|
|
--gnome-terminal
|
|
|-bash--bash--pstree
|
|
|
|
uws@tux>exec bash
|
|
uws@tux>pstree
|
|
--gnome-terminal
|
|
|-bash--pstree
|
|
\end{lstlisting}
|
|
|
|
\subsection{Ein-/Ausgabekanal}
|
|
|
|
In dem nachfolgenden Beispiel werden neue Eingabe- und Ausgabekan"ale definiert.\\
|
|
|
|
\listBash
|
|
\begin{lstlisting}[captionpos=b, caption=DemoExec.sh, label=lst:bash]
|
|
uws@tux>cat DemoExec.sh
|
|
#!/bin/env bash
|
|
#--------------------------------------------------------------------------
|
|
#
|
|
# Example to create File-Descriptors
|
|
#
|
|
#--------------------------------------------------------------------------
|
|
#
|
|
# Help
|
|
printf "\nDemo create File-Descriptor.\n"
|
|
printf "============================\n"
|
|
printf "exec Ziffer>Ziel\t\tAusgabekanal anlegen\n"
|
|
printf "exec Ziffer<Quele\t\tEingabekanal anlegen\n "
|
|
printf "exec Ziffer<>Datei\tEin/Ausgabekanal anlegen\n"
|
|
printf "Befehl >&Nr\t\t\t\t\tAusgabe auf Kanal Nr.\n"
|
|
printf "exec Ziffer>&-\t\t\tAusgabkanal loeschen\n"
|
|
printf "exec Ziffer<&-\t\t\tEingabekanal loeschen\n"
|
|
printf "\nJeder angelegter Kanal muss separat geloescht werden.\n"
|
|
printf "===================================================\n\n"
|
|
|
|
# Create test data
|
|
printf "First string\nSecond string\nThird string\n " > data1.txt
|
|
printf "one\ntwo\nthree\n" > data2.txt
|
|
|
|
# Create Ausgabekanal
|
|
printf " Anlegen Ausgabekanal 3.\n"
|
|
exec 3>data3.txt
|
|
printf " Anlegen Eingabekanal 4.\n"
|
|
exec 4<data1.txt
|
|
printf " Anlegen Ein-/Ausgabekanal 5.\n"
|
|
exec 5<>data5.txt
|
|
|
|
# Setzen Umleitung stdout und stderr
|
|
exec >data6.txt 2>data.err
|
|
echo "Das kommt in der Datei."
|
|
|
|
# Ausgabe in Kanal 3
|
|
echo "Das kommt in den Kanal 3." >&3
|
|
echo " Die einzelne Anweisung zur Umleitung ist nicht noetig."
|
|
|
|
# Erzeugen einer Fehlermeldung
|
|
ls new.txt
|
|
|
|
# Auslesen Kanal 4 und schreiben auf Kanal 3-
|
|
read A <&4
|
|
echo $A >&3
|
|
|
|
# Benutze den Ein-/Ausgabekanal 5.
|
|
tail -l <&5
|
|
echo "Neue Zeile" >&5
|
|
|
|
# Schliessen der Kanaele
|
|
exec 3>&-
|
|
exec 4<&-
|
|
exec 5>&-
|
|
exec 5<&-
|
|
|
|
exit 0
|
|
\end{lstlisting}
|
|
\end{flushleft}
|