Skip to content

Commit 29206e5

Browse files
committed
Updates of variables.
1 parent 5d3a2fd commit 29206e5

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

presentation/linux_bash_metacentrum_course.tex

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ \subsection{Globbing, wildcards, quotes}
16731673
\begin{frame}{BASH globing and wildcards}
16741674
\label{globbing}
16751675
\begin{itemize}
1676-
\item BASH itself doesn't recognize regular expressions --- its wildcards have some of functions of regular expressions (from slide~\ref{regexp}) and can look similarly, but behave differently --- Do not confuse!
1676+
\item BASH itself doesn't recognize regular expressions (from slide~\ref{regexp}) --- its wildcards have some of functions of regular expressions and can look similarly, but behave differently --- Do not confuse!
16771677
\item \texttt{?} --- Replaces any single character
16781678
\item \texttt{*} --- Replaces any number of any characters (\texttt{ls a*} lists all files starting with \enquote{a})
16791679
\item \texttt{[]} --- Range or a~list --- \texttt{[abcdef]} and \texttt{[a-f]} are same
@@ -1741,7 +1741,7 @@ \subsection{Variables}
17411741
VARIABLE='variablevalue' # Set new variable and its value
17421742
# Or replace existing variable by new value
17431743
export EDITOR='/usr/bin/vim' # Set new default text editor
1744-
LISTFILES="$(ls -1)" # Get output of command 'ls -1' into the variable
1744+
LISTFILES="$(ls)" # Get output of command 'ls -1' into the variable
17451745
echo "${LISTFILES}" # See content of the variable LISTFILES
17461746
export GREP_OPTIONS='--color=auto' # Colored grep (see further)
17471747
unset VARIABLENAME # Drop variable and its value
@@ -1759,14 +1759,14 @@ \subsection{Variables}
17591759
echo '$A' # Single quotes preserve literal value
17601760
$A # We see variable's name, not its content
17611761
echo "$A" # Double quotes preserve literal value, except $, `, \
1762-
abcdef # This also works
1763-
echo `$A` # Text between back ticks is evaluated and launched
1762+
abcdef # This also works; not needed here
1763+
echo `$A` # Text between back ticks is evaluated as a command and launched
17641764
abcdef: command not found # There is no command "abcdef"...
17651765
echo $($A) # Same as `...`, this is now recommended way, `...` is legacy
1766+
# Commonly used to fill variable by output of some command, e.g.
1767+
FQTOPROCESS=$(find "${DATADIR}" -type f -name "*.f*q")
17661768
echo "Hi, dear $USER" # Compare this and following command...
17671769
echo 'Hi, dear $USER' # Single quotes do not evaluate variables
1768-
A=abcde # OK
1769-
echo $A # abcde
17701770
\end{bashcode}
17711771
\end{frame}
17721772

@@ -1776,19 +1776,19 @@ \subsection{Variables}
17761776
echo $B # abcd
17771777
C=abcd\$e # \ escapes next character - it is loosing its special meaning
17781778
echo $C # abcd$e
1779-
D='abcd$e' # '...' keep literal value of the content
1780-
echo $D # abcd$e
1779+
C='abcd$e' # '...' keep literal value of the content; as above
17811780
# Next command breaks shell - incomplete quotes " - pres then Ctrl+C
1782-
E=ab"cde # The variable should contain incomplete quotes ", it fails
1783-
echo $E # Nothing - empty
1784-
F=ab\"cde # \ escapes next character - it is loosing its special meaning
1785-
echo $F # ab"cde
1786-
G='ab"cde' # '...' keep literal value of the content
1787-
echo $G # ab"cde
1788-
H=abc${USER}de # $USER wouldn't work - {} are needed
1789-
echo $H # abcvojtade # To add output of command into the variable
1790-
I="abc$(echo ${USER} | tr [:lower:] [:upper:])de" # Modification of var.
1791-
echo $I # See what happened with content of $USER
1781+
D=ab"cde # The variable should contain incomplete quotes ", it fails
1782+
echo $D # Nothing - empty
1783+
E=ab\"cde # \ escapes next character - it is loosing its special meaning
1784+
echo $E # ab"cde
1785+
E='ab"cde' # '...' keep literal value of the content; as above
1786+
F=abc${USER}de # $USER wouldn't work - {} are needed
1787+
echo $F # abcvojtade # To add output of command into the variable
1788+
G="abc$(echo ${USER} | tr [:lower:] [:upper:])de" # Modification of var.
1789+
echo $G # See what happened with content of $USER
1790+
H=abc def # Error: command "def" not found... Why? Fixing:
1791+
H='abc def' # "echo $H" outputs "abc def" - typical problem with paths
17921792
\end{bashcode}
17931793
\end{frame}
17941794

0 commit comments

Comments
 (0)