Shell | ? | * | *.txt | # | % | {3..7} |
---|---|---|---|---|---|---|
RE | . | .* | \.txt$ | ^ | $ | {3,7} |
Shell | \ "" '' |
$'' |
${} |
eval |
---|---|---|---|---|
RE | \ [] |
\(\) \+ ... |
Je vůbec nějaký ne-alfanumerický znak,
který nemá v shellu speciální význam?
30 40 50 60 70 80 90 100 110 120
-- ---------------------------------
0: ( 2 < F P Z d n x
1: ) 3 = G Q [ e o y
2: * 4 > H R \ f p z
3: ! + 5 ? I S ] g q {
4: " , 6 @ J T ^ h r |
5: # - 7 A K U _ i s }
6: $ . 8 B L V ` j t ~
7: % / 9 C M W a k u DEL
8: & 0 : D N X b l v
9: ' 1 ; E O Y c m w
Různé kontexty — Různá interpretace
LC_COLLATE=cs_CZ.UTF-8 sort
#!/bin/sh
PHP_FCGI_MAX_REQUESTS=10000
export PHP_FCGI_MAX_REQUESTS
exec /usr/local/bin/php-cgi
rm *.{txt,bak} 2>"$err"
for file; do
rm -- "${file}" || exit
done
|
&
;
(
)
<
>
space
tab
newline
p1<f1|p2>f2;p3&p4
p1 <f1 | p2 >f2 ; p3 & p4
IFS=:
ll $PATH
ls -l /bin:/usr/bin:/usr/local/bin
ls -l /bin /usr/bin /usr/local/bin
ls |
-l |
/bin |
/usr/bin |
/usr/local/bin |
shell: exec…(program, parameters…)
program: int main(int argc, char *argv[]) { … }
$var
"$var"
"${var}"
"${var:=default}"
declare -A array=( key1 value1 key2 value2 … )
declare -A array=( [key1]=value1 [key2]=value2 … )
""
f="file name"; cp "$f" /tmp
""
f=file name; cp file name /tmp
""
f=file name; cp file name /tmp
grep "a.*b"
""
f=file name; cp file name /tmp
grep a.*b
""
f=file name; cp file name /tmp
grep a.*b
cat >f <<"DOC"
$s_\$$__
DOC
""
f=file name; cp file name /tmp
grep a.*b
cat >f <<DOC
$s_\$$__
DOC
""
kontraproduktivníecho "$text"
""
kontraproduktivníecho "Result: "$text""
""
kontraproduktivníecho Result: $text
""
kontraproduktivníecho "Result: \"$text\""
""
kontraproduktivníecho Result: "$text"
""
kontraproduktivníecho "Result: "$text""
IFS=:; find $PATH -name command
""
kontraproduktivníecho "Result: "$text""
IFS=:; find $PATH -name command
[[
nebo case
SP=*.txt ; ERE=^a.*b$ [[ $var == $SP ]] [[ $var =~ $ERE ]] |
case $var in
[a-z]|"") …;;
"*") …;;
*) …;;
esac
|
for file in $( ls ); …
for file in $( ls ); …
for file in *; …
cat file | while read; do …; done
cat file | while read; do …; done
while read; do …; done <file
read line; declare -p line
read line; declare -p line
read; declare -p REPLY
echo $PATH
$( echo $PATH )
PATH=$( echo $PATH ):/new/dir
PATH=$( echo $PATH ):/new/dir
PATH=$PATH:/new/dir
PATH=$( echo $PATH ):/new/dir
PATH=$PATH:/new/dir
PATH+=:/new/dir
echo $PATH
printf '%s\n' $( echo $PATH | tr : ' ' )
printf '%s\n' $( echo $PATH | tr : ' ' )
printf '%s\n' $( tr : ' ' <<<$PATH )
printf '%s\n' $( echo $PATH | tr : ' ' )
printf '%s\n' $( tr : ' ' <<<$PATH )
printf '%s\n' ${PATH//:/ }
printf '%s\n' $( echo $PATH | tr : ' ' )
printf '%s\n' $( tr : ' ' <<<$PATH )
printf '%s\n' ${PATH//:/ }
printf %s\\n ${PATH//:/ }
printf '%s\n' $( echo $PATH | tr : ' ' )
printf '%s\n' $( tr : ' ' <<<$PATH )
printf '%s\n' ${PATH//:/ }
printf %s\\n ${PATH//:/ }
IFS=:; printf %s\\n $PATH
for arg in $*; …
for arg in $*; …
for arg in "$@"; …
for arg in $*; …
for arg in "$@"; …
for arg; …
echo "my_script: …"
echo "my_script: …"
echo "$0: …"
if [ -z "$var" ]; then var=default; fi
if [ -z "$var" ]; then var=default; fi
[ -z "$var" ] && var=default
if [ -z "$var" ]; then var=default; fi
[ -z "$var" ] && var=default
: ${var:=defaul}
var=$( echo "$var" | sed 's/foo/bar/' )
var=$( echo "$var" | sed 's/foo/bar/g' )
var=$( echo "$var" | sed 's/foo/bar/' )
var=$( echo "$var" | sed 's/foo/bar/g' )
var=${var/foo/bar}
var=${var//foo/bar}
echo "$var" | sed 's/^foo//'
echo "$var" | sed 's/foo$//'
echo "$var" | sed 's/^foo//'
echo "$var" | sed 's/foo$//'
echo "${var#foo}"
echo "${var%foo}"
len=$( echo -n "$var" | wc -c )
len=$( echo -n "$var" | wc -c )
len=${#var}
for i in "$@"; do
if [ -d "$i" ]; then dirs="$dirs $i"; fi
done
ls -ld $dirs
for i; do
[ -d "$i" ] && dirs+=( "$i" )
done
ls -ld "${dirs[@]}"
var=''
for arg; do var+=,$arg; done
echo "$var" | sed 's/^,//'
echo "$var" | sed 's/,//'
echo "$var" | sed s/,//
echo "$var" | sed 1s/,//
var=()
for arg; do var+=( "$arg" ); done
IFS=,; echo "${var[*]}"
if podmínka1; then
dělej
else
chyba
exit 1
fi
if podmínka1; then
if podmínka2; then
dělej
else
chyba
exit 1
fi
else
chyba
exit 1
fi
if ! podmínka1; then
chyba
exit 1
fi
if ! podmínka2; then
chyba
exit 1
fi
dělej
err() { chyba; exit 1; }
if ! podmínka1; then
chyba
exit 1
fi
if ! podmínka2; then
chyba
exit 1
fi
dělej
err() { chyba; exit 1; }
if ! podmínka1; then
chyba
exit 1
fi
podmínka2 || err
dělej
err() { chyba; exit 1; }
podmínka1 || err
podmínka2 || err
dělej
test …
⇒ [[ … ]]
⇒ [ … ]
source file
⇒ . file
$(cmd)
⇒ `cmd`
function f
⇒ f()
date +%Y-%m-%d_%H:%M:%S
⇒ date +%F_%T
grep -E
⇒ egrep
gzip -d
⇒ gunzip
cat file | filter
⇒ filter <file
filter file
read
a proměnná REPLY
[ -z string ]
⇒ [ string ]
(( value != 0 ))
⇒ (( value ))
for i in "$@"
⇒ for i
select i in "$@"
⇒ select i
cmd; if [ $? -eq 0 ]; then …; fi
if cmd; then …; fi
cmd && …
declare -i var; var=foo
declare -i var; var+=1
kill last_job
⇒ kill %+
fg %+
⇒ fg
$(pwd)
⇒ $PWD
⇒ ~+
$(whoami)
⇒ $USER
$HOME
⇒ ~
$CDPATH
export LESS=-eX; less file
{a..z}
{00..100..10}
file.{txt,old}
text{,,,}
*
?
[]
shopt -s extglob
!(list|…)
?(list|…)
@(list|…)
*(list|…)
+(list|…)
f=/foo/bar/baz.xyz; cmd "$f"
f(){ cmd;}
f()(cmd)
alias c=cmd
c
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
grep -Ex '.{5}'<slovnik.txt | grep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
grep -Ex '.{5}'<slovnik.txt | grep "e.i.e"
grep -Ex '.{5}' slovnik.txt | grep "e.i.e"
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
grep -Ex '.{5}'<slovnik.txt | grep "e.i.e"
grep -Ex '.{5}' slovnik.txt | grep "e.i.e"
grep -Ex .{5} slovnik.txt | grep e.i.e
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
grep -Ex '.{5}'<slovnik.txt | grep "e.i.e"
grep -Ex '.{5}' slovnik.txt | grep "e.i.e"
grep -Ex .{5} slovnik.txt | grep e.i.e
grep -Ex .{5} slovnik.txt|grep e.i.e
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
grep -Ex '.{5}'<slovnik.txt | grep "e.i.e"
grep -Ex '.{5}' slovnik.txt | grep "e.i.e"
grep -Ex .{5} slovnik.txt | grep e.i.e
grep -Ex .{5} slovnik.txt|grep e.i.e
egrep ^.{5}$ slovnik.txt|grep e.i.e
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
< slovnik.txt grep -ex '.\{5}\' | grep -e "e.i.e"
< slovnik.txt grep -ex '.\{5}\' | egrep "e.i.e"
< slovnik.txt grep -x '.\{5}\' | grep "e.i.e"
< slovnik.txt grep -x '.....' | grep "e.i.e"
< slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
<slovnik.txt grep -Ex '.{5}' | grep "e.i.e"
grep -Ex '.{5}'<slovnik.txt | grep "e.i.e"
grep -Ex '.{5}' slovnik.txt | grep "e.i.e"
grep -Ex .{5} slovnik.txt | grep e.i.e
grep -Ex .{5} slovnik.txt|grep e.i.e
egrep ^.{5}$ slovnik.txt|grep e.i.e
egrep ^.{5}$ *.txt|grep e.i.e
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
egrep ^.{5}$ slovnik.txt|grep e.i.e
egrep ^.{5}$ *.txt|grep e.i.e
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
egrep ^.{5}$ *.txt|grep e.i.e
alias w='grep -Ex .{5} *.txt|grep'
w(){ egrep ^.{5}$ *.txt|grep "$1";}
w()(egrep ^.{5}$ *.txt|grep "$@")
w e.i.e
< slovnik.txt grep -e '^.\{5}\$' | grep -e "^e.i.e"
egrep ^.{5}$ *.txt|grep e.i.e
alias w='grep -Ex .{5} *.txt|grep'
w(){ egrep ^.{5}$ *.txt|grep "$1";}
w()(egrep ^.{5}$ *.txt|grep "$@")
w e.i.e
alias a=alias
a g=egrep
a w='g ^.{5}$ *.txt|g'
w e.i.e
w e.i.e|g x