File indexing completed on 2024-05-19 15:23:19
0001 # basic types: 0002 echo 'single quoted string' 0003 echo "double quoted string" 0004 echo $'string with esc\apes\x0din it' 0005 echo $"string meant to be translated" 0006 0007 0008 # comments: 0009 # this is a comment 0010 #this too 0011 echo this is#nt a comment 0012 dcop kate EditInterface#1 #this is 0013 grep -e "^default/linux/amd64/" |\ #this is not a comment but #this is 0014 mkdir this\ isnt\ #a\ comment 0015 mkdir this\ isnt\\\;#a\ comment 0016 mkdir this\\ #is a comment 0017 0018 # brace expansion 0019 mv my_file.{JPG,jpg} 0020 echo f.{01..100..3} f.{#..Z} f.{\{..\}} f.{$i..$j..$p} 0021 echo f.{01..100} f.{a..Z} f.{'a'..$Z} 0022 # no brace expansion 0023 echo f.{..100} f.{a..Z..} 0024 0025 0026 # special characters are escaped: 0027 echo \(output\) \&\| \> \< \" \' \* 0028 0029 0030 # variable substitution: 0031 echo $filename.ext 0032 echo $filename_ext 0033 echo ${filename}_ext 0034 echo text${array[$subscript]}.text 0035 echo text${array["string"]}.text 0036 echo short are $_, $$, $?, ${@}, etc. 0037 echo ${variable/a/d} 0038 echo ${1:-default} 0039 echo ${10} $10a 0040 echo $! $=! 0041 0042 0043 # expression subst: 0044 echo $(( cd << ed + 1 )) 0045 0046 0047 # command subst: 0048 echo $(ls -l) 0049 echo `cat myfile` 0050 0051 0052 # file subst: 0053 echo $(<$filename) 0054 echo $(</path/to/myfile) 0055 0056 # process subst: 0057 sort <(show_labels) | sed 's/a/bg' > my_file.txt 2>&1 0058 0059 0060 # All substitutions also work in strings: 0061 echo "subst ${in}side string" 'not $inside this ofcourse' 0062 echo "The result is $(( $a + $b )). Thanks!" 0063 echo "Your homedir contains `ls $HOME |wc -l` files." 0064 0065 0066 # Escapes in strings: 0067 p="String \` with \$ escapes \" "; 0068 0069 0070 # keywords are black, builtins dark purple and common commands lighter purple 0071 set 0072 exit 0073 login 0074 0075 0076 # Other colorings: 0077 error() { 0078 cat /usr/bin/lesspipe.sh 0079 runscript >& redir.bak 0080 exec 3>&4 0081 } 0082 0083 0084 # do - done make code blocks 0085 while [ $p -lt $q ] 0086 do 0087 chown 0644 $file.$p 0088 done 0089 0090 0091 # braces as well 0092 run_prog | sort -u | 0093 { 0094 echo Header 0095 while read a b d 0096 do 0097 echo $a/$b/$c 0098 done 0099 echo Footer 0100 } 0101 0102 0103 # Any constructions can be nested: 0104 echo "A long string with $( 0105 if [ $count -gt 100 ] ; then 0106 echo "much" 0107 else 0108 echo "not much" 0109 fi ) substitutions." ; 0110 0111 0112 # Even the case construct is correctly folded: 0113 test -f blaat && 0114 ( do_something 0115 case $p in 0116 *bak) 0117 do_bak $p 0118 ;; 0119 *) 0120 dont_bak $p 0121 ;; 0122 esac 0123 ) # despite the extra parentheses in the case construction. 0124 0125 0126 # more control flow 0127 while :; 0128 break 0129 continue 0130 return 0131 done 0132 0133 0134 # variable assignments: 0135 DIR=/dev 0136 p=`ls` 0137 LC_ALL="nl" dcop 'kate*' 0138 _VAR=val 0139 ARR=(this is an array) 0140 ARR2=([this]=too [and]="this too") 0141 usage="$0 -- version $VERSION 0142 Multiple lines of output 0143 can be possible." 0144 ANSWER=yes # here 'yes' isn't highlighed as command 0145 0146 0147 # Some commands expect variable names, these are colored correctly: 0148 export PATH=/my/bin:$PATH BLAAT 0149 export A B D 0150 local p=3 x y='\' 0151 read x y z <<< $hallo 0152 unset B 0153 declare -a VAR1 VAR2 && exit 0154 declare less a && b 0155 declare a=(1 2) 0156 getopts :h:l::d arg 0157 read #comment 0158 let a=4+4 3+a b=c+3 d+3 d*4 # * is a glob 0159 0160 # options are recoqnized: 0161 zip -f=file.zip 0162 ./configure --destdir=/usr 0163 make destdir=/usr/ 0164 0165 0166 # [[ and [ correctly need spaces to be regarded as structure, 0167 # otherwise they are patterns (currently treated as normal text) 0168 if [ "$p" == "" ] ; then 0169 ls /usr/bin/[a-z]* 0170 elif [[ $p == 0 ]] ; then 0171 ls /usr/share/$p 0172 fi 0173 0174 # Fixed: 0175 ls a[ab]* # dont try to interprete as assignment with subscript (fixed) 0176 a[ab] 0177 a[ab]=sa 0178 0179 0180 # Here documents are difficult to catch: 0181 cat > myfile << __EOF__ 0182 You're right, this is definitely no bash code 0183 But ls more $parameters should be expanded. 0184 __EOF__ 0185 0186 0187 # quoted: 0188 cat << "EOF" | egrep "this" >&4 # the rest of the line is still considered bash source 0189 You're right, this is definitely no bash code 0190 But ls more $parameters should be expanded. :-> 0191 EOF 0192 0193 cat <<bla || exit 0194 bla bla 0195 bla 0196 0197 0198 # indented: 0199 if true 0200 then 0201 cat <<- EOF 0202 Indented text with a $dollar or \$two 0203 EOF 0204 elif [ -d $file ]; then 0205 cat <<- "EOF" 0206 Indented text without a $dollar 0207 EOF 0208 fi 0209 0210 if ! { cmd1 && cmd2 ; }; then echo ok ; fi 0211 if ! {cmd1 && cmd2}; then echo ok ; fi 0212 if ! cmd1 arg; then echo ok ; fi 0213 0214 case 1 in 0215 2) echo xxx; 0216 ;; 0217 ?) foo || yyy ; foo abc || echo abc ;; 0218 1) echo yyy; 0219 esac 0220 0221 ls #should be outside of case 1 folding block 0222 0223 for i in `ls tests/auto/output/*.html`; do 0224 refFile=`echo $i | sed -e s,build,src, | sed -e s,output,reference, | sed -e s,.html,.ref.html,` 0225 cp -v $i $refFile 0226 done 0227 0228 ## >Settings >Configure Kate >Fonts & Colors >Highlitghing Text Styles >Scripts/Bash >Option >Change colors to some distinct color 0229 ## 1- In following line the -ucode should not be colored as option 0230 0231 pacman -Syu --needed intel-ucode grub 0232 pacman -syu --needed intel-ucode grub 0233 0234 [[ $line_name =~ \{([0-9]{1,})\}\{([0-9]{1,})\}(.*) ]] 0235 [[ $name =~ (.*)_(S[0-9]{2})(E[0-9]{2,3}[a-z]{0,1})_(.*) ]] 0236 rm /data/{hello1,hello2}/input/{bye1,$bye2}/si{a,${b},c{k,p{e,a}}}/*.non 0237 rm /data/{aa,{e,i}t{b,c} # Not closed 0238 rm /data/{aa,{e,i}t{b,c}} 0239 rm /data/{aa,{i}} 0240 rm /data{aa{bb{cc{dd}}}} 0241 rm /data{aaa`aaa}aa`aaa}a 0242 0243 # TODO ` 0244 0245 # commands 0246 abc 0247 cp 0248 : 0249 . 0250 :#nokeyword 0251 path/cmd 0252 ec\ 0253 ho 0254 2 0255 'a'c 0256 $ab 0257 ${ab}c 0258 \ a 0259 !a 0260 'a'[ 0261 \ [ 0262 !a[ 0263 a{}d 0264 a{bc}d 0265 a{b,c}d 0266 a'b'c 0267 a$bc 0268 a${bc}d 0269 a\ b 0270 a!b 0271 0272 # commands + params 0273 shortopt -ol -f/fd/fd -hfd/fds - -ol'a'b -f'a'/fd/fd -h'a'fd/fds 0274 longopt --long-a --long-b=value --file=* --file=file* --file=dir/file 0275 longopt --long-a'a'b --long'a'-b=value --fi'a'le=* 0276 noopt 3 3d -f -- -f --xx dir/file 0277 opt param#nocomment ab'a'cd ~a .a #comments 0278 path path/file dir/ / // 3/f a@/ 'a'/b d/'a'b a\ d/f f/f\ 0279 ile 0280 path ~ ~/ ~a/ . .. ./a ../a 0281 path /path/* /path/f* /path/f@ /path/f@(|) {a/b} a{b}/c a/b{c} a/{b} a/{b}c 0282 glob ? * ?f *f f* f? **/ ~/* ~* /path/f* 'a'* 'a'f/? 0283 # ksh pattern is in conflict with extended pattern 0284 extglob @ @(*) @(f*|f??(f)) f!(+(?(@(*(f)f)f)f)f)f @'a'@(|) a@(?) 0285 echo *.*~(lex|parse).[ch](^D^l1) 0286 echo /tmp/foo*(u0^@:t) *(W,X) *(%W) 0287 subs f! f!! f!s 'a'!s \( $v {a,b} {a} {a}/d {a\,} {a,} {a,\},b} ds/{a,b}sa/s 0288 0289 ls !?main 0290 ls $(echo NF)(:a) 0291 ls ${(s.:.)PATH} | grep '^...s' 0292 ls (#i)*.pmm 0293 ls (#ia1)README 0294 ls (*/)#bar 0295 ls (../)#junk2/down.txt(:a) 0296 ls (^(backup*|cache*|list*|tmp)/)##*(.) 0297 ls (_|)fred.php 0298 ls (dev*|fred*|joe*)/index* 0299 ls (x*~x[3-5]) 0300 ls (xx|yy) 0301 ls *(*@) 0302 ls *(+nt) 0303 ls *(.)^php~*.c~*.txt 0304 ls *(.L-20) 0305 ls *(.L0) 0306 ls *(.Om[1,5]) 0307 ls *(.^m0) 0308 ls *(.e#age 2017-10-01:00:00:00 2017-10-08:23:59:59#) /tmp 0309 ls *(.e-age 2018/09/01 2018/01/01-) 0310 ls *(.f644) 0311 ls *(.g:root:) 0312 ls *(.m-1) 0313 ls *(.mM+6) 0314 ls *(.mh+3) 0315 ls *(.mh-3) 0316 ls *(.mh3) 0317 ls *(.mw+2) 0318 ls *(.om[0,5]e-age 2017/09/01 2017/10/01-) 0319 ls *(.om[2,$]) old/ 0320 ls *(.rwg:nobody:u:root:) 0321 ls *(.u:apache:) 0322 ls *(/) 0323 ls *(/^F) 0324 ls *(L0f.go-w.) 0325 ls *(Lk+100) 0326 ls *(Lm+2) 0327 ls *(R) 0328 ls *([1,10]) 0329 ls *(^/,f44?,f.gu+w.,oL+rand,oe:"$cmd -x":P:echo::h) 0330 ls *(m4) 0331 ls *(mh0) 0332 ls *(mw3) 0333 ls *(${globqualifiers}N) 0334 ls *(\^'/') 0335 ls **.php 0336 ls **/*(#ia2)readme 0337 ls **/*(-@) 0338 ls **/*(.) 0339 ls **/*(.:g-w:) 0340 ls **/*(.Lm+10) 0341 ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':) 0342 ls **/*(u0WLk+10m0) 0343 ls **/*.(js|php|css)~(djr|libs|dompdf)/*~*/junk/* 0344 ls **/*.(js|php|css)~(libs|locallibs|test|dompdf)/* 0345 ls **/*.(php|inc) 0346 ls **/*.(php|inc)~(libs|locallibs)/*(.OL[1,5]) 0347 ls **/*.txt(D.om[1,5]) 0348 ls **/*~*(${~${(j/|/)fignore}})(.^*) 0349 ls **/*~*vssver.scc(.om[1,20]) 0350 ls **/*~pdf/*(.m0om[1,10]) 0351 ls **/^(vssver.scc|*.ini)(.om[1,20]) 0352 ls **/^vssver.scc(.om[1,20]) 0353 ls **/index.php~dev*(/*)## 0354 ls **/main.{php,js,css} 0355 ls *.(jpg|gif|png)(.) 0356 ls *.*(e-age 2018/06/01 now-) 0357 ls *.*(mM4) 0358 ls *.*~(lex|parse).[ch](^D^l1) 0359 ls *.*~[a-m]*(u:nobody:g:apache:.xX) 0360 ls *.c(#q:s/#%(#b)s(*).c/'S${match[1]}.C'/) 0361 ls *.c(:r) 0362 ls *.c~lex.c 0363 ls *.h~(fred|foo).h 0364 ls *.{aux,dvi,log,toc} 0365 ls *.{jpg,gif}(.N) 0366 ls *[^2].php~*template* 0367 ls *y(2|).cfm 0368 ls *y2#.cfm 0369 ls *~*.*(.) 0370 ls ./*(Om[1,-11]) 0371 ls ./**/*(/od) 2> /dev/null 0372 ls ./**/*.(php|inc|js) 0373 ls ./**/*.{inc,php} 0374 ls ./*.back(#qN) 0375 ls ./{html,live}/**/*.(php|inc|js)~(**/wiki|**/dompdf)/* 0376 ls /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'}) 0377 ls <-> <-6> <4-> <4-5> 0<-> {1..5} {2,3} {00..03} (4|5) [3-4] [3-47-8] 0? ?2 *2 0378 ls =some_file 0379 ls DATA_[0-9](#c,4).csv 0380 ls DATA_[0-9](#c3).csv 0381 ls DATA_[0-9](#c4,).csv 0382 ls DATA_[0-9](#c4,7).csv 0383 ls PHP*/**/*.php 0384 ls [01]<->201[45]/Daily\ report*.csv(e#age 2014/10/22 now#) 0385 ls ^*.(css|php)(.) 0386 ls ^?*.* 0387 ls ^?*.*(D) 0388 ls ^?*.[^.]*(D) 0389 ls a(#c3).txt 0390 ls file<20-> 0391 ls foot(fall)#.pl 0392 ls fred<76-88>.pl 0393 ls fred<76->.pl 0394 ls fred^erick* 0395 ls fred{09..13}.pl 0396 ls fred{joe,sid}.pl 0397 ls x*~(x3|x5) 0398 ls x*~^x[3,5] 0399 ls x*~x[3,5] 0400 ls x^[3,5] 0401 ls y2#.cfm y{2,}.cfm y(2|).cfm {y2,y}.cfm (y|y2).cfm y*.cfm 0402 ls {^dev*,}/index.php(.N) 0403 ls {_,}fred.php 0404 ls {p..q}<5->{1..4}.(#I)php(.N) 0405 ls ~1/*(.om[1]) 0406 ls **/*.php~*junk*/* #find all calls to mail, ignoring junk directories 0407 ls **/(*.cfm~(ctpigeonbot|env).cfm) 0408 ls **/*.{js,php,css}~(libs|temp|tmp|test)/* 0409 ls */*.php~libs/*~temp/*~test/* 0410 ls **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.) 0411 ls **/*.(js|php|css)~(libs|temp|test)/* 0412 ls **/*.(js|php|css)~libs/*~temp/*~test/* 0413 ls report/**/*.{inc,php} # searching for a php variable 0414 ls *.log(Ne-age 2006/10/04:10:15 2006/10/04:12:45-) 0415 ls $(echo /c/aax/*(.om[1]))(+cyg) & 0416 ls *~vssver.scc(.om[1]) 0417 ls /c/aax/*(.om[1]+cyg) 0418 ls ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"} 0419 ls [[[[]]x* 0420 0421 2 - f -f 0422 !a -f 0423 'a' -f 0424 $a -f 0425 ! cmd 0426 0427 # coproc command (#460301) 0428 coproc ls thisfiledoesntexist 2>&1 0429 coproc { ls thisfiledoesntexist; read; } 2>&1 0430 0431 # redirections (prefix) 0432 <<<s cat 0433 <<<'s' cat 0434 <<<'s's cat 0435 <<<s's's cat 0436 <<<s${s}s cat 0437 <<< s${s}s cat 0438 >&2 cat 0439 <f cat 0440 2>3 cat 0441 2>&3 cat 0442 2>& 3 cat 0443 2>f cat 0444 &>f cat 0445 2>>(xless) cat 0446 2<<(xless) cat 0447 2>>(xless)cat 0448 2<<(xless)cat 0449 0450 # redirections 0451 cat f>2 0452 cat d/f>2 0453 cat d/f >2 0454 cat d/f >& 2 0455 cat >2 d/f 0456 cat > 2 0457 cat <(echo) <(echo a) <(echo a/f) <(echo ) <(echo a ) <(echo a/f ) 0458 cat 2>>(xless) 0459 cat 2<<(xless) 0460 cat 2>&1 &>f &>>f 2<&1- 2<>f 2<<heredoc 0461 bla bla 0462 heredoc 0463 <<-'h' cat 0464 bla 0465 h 0466 <<"'" cat 0467 bla 0468 ' 0469 r=$(xxx $@ 2>&1) 0470 0471 # branches 0472 cat a|cat 0473 cat a&cat 0474 cat a||cat 0475 cat a&&cat 0476 cat a;cat 0477 cat a | cat 0478 cat a & cat 0479 cat a || cat 0480 cat a && cat 0481 cat a ; cat 0482 cat a'a';cat 0483 0484 # substitutions 0485 echo '' 'a' '\' "" "a" "\\" "$a" "a""a"'a''a' a'b'c a"b"c a$'\n'c 0486 echo a!bc a{a}b a{b,c}d a{b,{d,e}}d a\ b 0487 echo a$bc a$b/c a${b}c a$((b-3))c a$(b)c a$(a b c)c 0488 echo ${a[*]} ${a[@]} ${a[${b}]} ${a:-x$z} ${a/g} ${a//f/f} ${a//f*/f*} 0489 echo ${!} ${!a} ${#a[1]} ${a:1:$b} $((++i,i--)) 0490 echo ${a:^v} ${=a:/#%a#?*/bla} ${x#??(#i)} ${das:-{}<a.zsh} 0491 echo ${(f)"$(<$1)"} ${${(Az)l}[$2]} ${(f)"$(eval ${(q)@[2,$]})"} 0492 echo ${(@)foo} ${(@)foo[1,2]} ${${(A)name}[1]} ${(AA)=name=...} ${(Q)${(z)foo}} 0493 echo ${(ps.$sep.)val} ${(ps.${sep}.)val} ${(s.$sep.)val} ${(s.)(.)val} 0494 echo ${(pr:2+3::_::$d:)var} ${(r:2+3::_::$d:)var} 0495 echo ${${:-=cat}:h} 0496 $foo:h34:a:gs/dfs/fds/:s/fds/d'd'f xyz $foo: $foo:O $foo:A 0497 3=$foo:QQQ xyz $a[3,$]:h3:t1:e 0498 echo ${${~foo}//\*/*.c} 0499 echo !$ !!:$ !* !!:* !-2:2 !:-3 !:2* !:2- !:2-3 !^ !:1 !!:1 0500 echo "$bg[blue]$fg[yellow]highlight a message" 0501 echo "$bg[red]$fg[black]${(l:42::-:)}" 0502 echo "${${(@)foo[2,4]}[2]}" 0503 echo "${(j::)${(@Oa)${(s::):-hello}}}" 0504 echo "${(j::)${(@Oa)${(s::):-hello}}}" 0505 echo "<a href='$url'>$anchortext</a>" 0506 echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 )) 0507 echo $a[${RANDOM}%1000] $a[${RANDOM}%11+10] 0508 echo $convtable[158] 0509 echo ${array[0]: -7 : + 22 } ${array[1]: num } 0510 echo ${parameter##word} ${parameter%%word} 0511 echo $f ' # $fred' 0512 echo $f:e $f:h $f:h:h $f:r $f:t $f:t:r $file:r 0513 echo ${(C)foo:gs/-/ /:r} ${(M)0%%<->} ${(j/x/s/x/)foo} ${(l:$COLUMNS::-:)} 0514 echo ${(l:3::0:)${RANDOM}} ${(s/x/)foo%%1*} ${0##*[!0-9]} 0515 echo ${a:2:2} ${a:2} ${a[1,3]} ${d/#?/} ${d/%?/} ${d[1,-2]} ${d[2,$]} 0516 echo ${d[2,-1]} ${file##*/} ${file%.*} ${texfilepath%/*.*} *(f:u+rx,o-x:) 0517 echo *(f:u+rx:) **/*(@-^./=%p) **/*(@-^./=%p) convert_csv.php(:a) 0518 cd $(locate -l1 -r "/zoo.txt$")(:h) # cd to directory of first occurence of a file zoo.txt 0519 cd ${$(!!)[3]:h} # cd to 3rd in list 0520 cd ${$(locate zoo.txt)[1]:h} 0521 cd ${drive}/inetpub/wwwdev/www.some.co.uk/ 0522 cd **/*.php(.om[1]:h) # cd to directory of newest php file 0523 cd - 0524 cd /tmp/test/;touch {1..5} {6,7,8,12} {00..03} 0525 cd ~www/admin 0526 chmod g+w **/* 0527 chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:) 0528 cp *.mp3(mh-4) /tmp # copy files less than 4 hours old 0529 cp -a file1 file # -a transfer permissions etc of file1 to file2preserve 0530 file **/*(D@) | fgrep broken 0531 file **/*(D@) | fgrep broken 0532 file=${1/#\//C:\/} # substitute / with c:/ Beginning of string 0533 file=${1/%\//C:\/} # substitute / with c:/ End of string 0534 file=${1/\//C:\/} # substitute / with c:/ ANYWHERE in string 0535 filelst+=($x) 0536 filelst[$(($#filelst+1))]=$x 0537 files=(${(f)"$(egrepcmd1l)"} ) 0538 files=(${(f)"$(ls *$**)"}(.N)) # ")` 0539 files=(**/*(ND.L0m+0m-2)) 0540 mkdir $f:h;touch $f 0541 mv Licence\ to\ Print\ Money.pdf !#^:gs/\\ // 0542 path=(${path:#$path_to_remove}) 0543 path=(${path:|excl}) 0544 pattern=${(b)str} 0545 pattern=${(q)str} 0546 print "$aa[one\"two\"three\"quotes]" 0547 print "$bg[cyan]$fg[blue]Welcome to man zsh-lovers" >> $TTY 0548 print $(( [#8] x = 32, y = 32 )) 0549 print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or 0550 print $(history -n -1|sed 's/.* //') 0551 print $aa[(e)*] 0552 print $ass_array[one] 0553 print $x $y 0554 print ${#path[1]} # length of first element in path array 0555 print ${#path} # length of "path" array 0556 print ${$( date )[2,4]} # Print words two to four of output of ’date’: 0557 print ${$(/sbin/ifconfig tun0)[6]} 0558 print ${${$( LC_ALL=C /sbin/ifconfig lo )[6]}#addr:} 0559 print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://} 0560 print ${${(Cs:-:):-fred-goat-dog.jpg}%.*} 0561 print ${${(z)$(history -n -1)}[-1]} 0562 print ${${(z)history[$((HISTCMD-1))]}[-1]} 0563 print ${(L)s// /-}.jpg 0564 print ${(L)s:gs/ /-/}.jpg 0565 print ${(S)foo//${~sub}/$rep} 0566 print ${(k)ass_array} # prints keys 0567 print ${(v)ass_array} # prints values 0568 print ${JUNK/%./_} # substitute last . for a _ 0569 print ${JUNK/.(#e)/_} # substitute last . for a _ 0570 print ${arr//(#m)[aeiou]/${(U)MATCH}} 0571 print ${array:t} 0572 print ${foo%%$'\n'} # strip out a trailing carriage return 0573 print ${foo//$'\n'} # strip out any carriage returns (some systems use \r) 0574 print ${foo//${~sub}/$rep} 0575 print ${foo: 1 + 2} 0576 print ${foo:$(( 1 + 2))} 0577 print ${foo:$(echo 1 + 2)} 0578 print ${foo:3} 0579 print ${param:&} (last substitute) 0580 print ${somevar//[^[:alnum:]]/_} # replace all non-alphanumerics with _ the // indicates global substitution 0581 print ${string[(r)d?,(r)h?]} 0582 print '\e[1;34m fred' 0583 print (*/)#zsh_us.ps 0584 print *(e:age 2006/10/04 2006/10/09:) 0585 print **/*(/^F) | xargs -n1 -t rmdir #delete empty directories 0586 print *.c(e_'[[ ! -e $REPLY:r.o ]]'_) 0587 print -C 1 $X # print each array element on it's own line 0588 print -l "${(s.:.)line}" 0589 print -l $MATCH X $match 0590 print -l $accum 0591 print -l *(n:t) # order by name strip directory 0592 print -l **/*(-@) 0593 print -l **/*(On:t) # recursive reverse order by name, strip directory 0594 print -r -- $^X.$^Y 0595 print -r -- ${(qq)m} > $nameoffile # save it 0596 print -rC1 /tmp/foo*(u0^@:t) 0597 print -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/) 0598 print -rC2 -- ${1:[...]}/*(D:t) 0599 print -rl $HOME/${(l:20::?:)~:-}* 0600 print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*} 0601 print -rl /**/*~^*/path(|/*) 0602 print {$((##n))..$((##y))}P\ 10P | dc 0603 print root@192.168.168.157:${PWD/test/live}v 0604 0605 0606 # conditions 0607 [ a ] 0608 [ -f f'f'f ] 0609 [ -f f]'f'f] ] 0610 [ -t 13 ] 0611 [ -t 13] ] 0612 [ -t 13] ] 0613 [ -v abc ] 0614 [ -z abc ] 0615 [ abc -ef abc ] 0616 [ abc -ef abc ] 0617 [ abc-ef -ef abc-ef ] 0618 [ abc == abc ] 0619 [ abc < abc ] 0620 [ abc -eq abc ] 0621 [[ abc -eq abc ]] 0622 [ 1+2 -eq 1+2 ] 0623 [[ 1+2 -eq 1+2 ]] 0624 [ a = b c ] 0625 [ -z 1 -a 1 -eq 1 ] 0626 [ 2 -eq 1 -o 1 -eq 1 ] 0627 ( [ a = b ] ) 0628 ([ a = b ]) 0629 [[ a = b c ]] 0630 [[ x =~ a(b c|$)' '{1,}[a[.digit.]] ]] 0631 [[ x =~ [ ] ]] 0632 [[ x =~ ([ ]) ]] 0633 [[ x =~ [ ]] 0634 [[ x =~ ([) ]] 0635 [[ (a =~ a) ]] 0636 [[ (a =~ 0637 a) ]] 0638 [[ a =~ a || a -eq 2 ]] 0639 [[ (a =~ a) || a -eq 2 ]] 0640 [[ a<b ]] 0641 [[ a <b ]] 0642 [[ a< b ]] 0643 [[ a < b ]] 0644 [[(! -d .)]] 0645 [[ ! -d . ]] 0646 [[ !(-d .) ]] 0647 [[ -f a || -f b ]] 0648 [[ -f a||-f b ]] 0649 [[ ! (a -eq b) ]] 0650 [ -d `echo .`] ] 0651 [[ -d `echo .`]] ]] 0652 [[ a != b && ${a}a = b${b} ]] 0653 [[ 0654 1 -eq 2 0655 ]] 0656 [[ 0657 1 0658 -eq 0659 2 0660 ]] 0661 [[ -""(#i)* == $x ]] 0662 [[ ]] 0663 [[ -f ]] 0664 [[ -f <0-99> ]] 0665 [[ $1 == <-> ]] 0666 [[ ?*<0-99> = <0-99> ]] 0667 [[ -f = ?*<0-99> ]] 0668 [[ a/sa[s = dsad?*<0-9>dsa$ds ]] 0669 [[ a/sa[s = dsad?*<0-9>ds/a$ds ]] 0670 [[ a =~ <1-2>a<->a<-2>a<2->a([!d]a?s[x[:alnum:]]|d?)p ]] 0671 [[ -n file*(#qN) ]] 0672 [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists. 0673 [[ $str = ${~pattern} ]] 0674 [[ $str = ${~pattern} ]] 0675 [[ "?" = ${(~j.|.)array} ]] 0676 ( [[ a = b ]] ) 0677 ([[ a = b ]]) 0678 0679 [[ #comm1 0680 #comm2 0681 ! #comm3 0682 p[1] #comm4 0683 == #comm5 0684 p[2] #comm6 0685 #comm7 0686 #comm8 0687 ]] 0688 0689 [[ #comm1 0690 #comm2 0691 -f #comme3 0692 #comm4 0693 p[2] #comm5 0694 #comm6 0695 #comm7 0696 ]] 0697 0698 [ a -eq 2 ] || [ a -eq 2] ] && [[ a -eq 2 ]] || [[ a != b ]]; 0699 [ a -eq 2 ]||[ a -eq 2] ]&&[[ a -eq 2 ]]||[[ a != b ]]; 0700 0701 ((3+1+a+$c*(x) & 0x4342_2fd+03-08_5/23#D9a@_^8)) 0702 ((1.3/(2-(a-4)))) 0703 0704 # they are not arithmetic evaluations... 0705 ((cmd && cmd) || cmd) 0706 $((cmd && cmd) || cmd) 0707 ((cmd && 0708 cmd) || cmd) 0709 $((cmd && 0710 cmd) || cmd) 0711 0712 print $(( [#_] sqrt(1e7) 0__39 1423e23 .2443 43.34 34.43e4 .d)) 0713 0714 { echo 0715 echo 0716 } 0717 { echo ; } 0718 { echo } 0719 {echo} 0720 {ls f} always {ls} 0721 {echo {a}} 0722 }echo 0723 echo {a} {a/b} a{b}/c a/b{c} a/{b} a/{b}c d/{{a}} 0724 echo {a{a{a}}} 0725 echo {a{a{a}a}a}a 0726 echo {a 0727 echo a} 0728 echo{a} 0729 echo{a{a{a}}} 0730 echo{a{a{a}a}a}a 0731 echo{a 0732 echo} 0733 0734 { {echo a} } 0735 { {echo a}a} } 0736 { { echo a } } 0737 { { echo a}a } } 0738 0739 { {echo a/b} } 0740 { {echo a/b}a} } 0741 { { echo a/b } } 0742 { { echo a/b}a } } 0743 0744 { {echo >a/b} } 0745 { {echo >a/b}a} } 0746 { { echo >a/b } } 0747 { { echo >a/b}a } } 0748 0749 {ab}c} 0750 {a,b}c} 0751 {ab}[} 0752 {a,b}[} 0753 0754 cat >f{oo,ar} 0755 0756 (echo ; echo) 0757 (echo 0758 echo) 0759 (echo a) 0760 test a -eq b 0761 0762 # functions 0763 a() { echo x; } 0764 a () { echo x; } 0765 function f { echo x; } 0766 kde.org() { echo x; } 0767 --func() { echo x; } 0768 noglob function f { echo x; } 0769 0770 # variables 0771 a=(a b c) 0772 a='a' 0773 a+=b 0774 a[1]='a' 0775 a[$i]='x' 0776 a[$(( 0777 2+4 0778 ))]='x' 0779 a=([a]=2 `echo` -s > 'ds') 0780 a=(#comment 0781 value#nocomment #comment) 0782 ) 0783 a=a cat 0784 a=`ls` cat 0785 a[2+3][d]=5 0786 0787 # control structure 0788 for name in a b c {d,e} ; do echo ; done 0789 for name; do echo ; done 0790 for name do echo ; done 0791 for ((i=0;i<5;++i)) ; do echo $i ; done 0792 for ((i=1;$#A[i];i++)) echo $A[$i] 0793 for c ({1..50}) {php ./test.php; sleep 5;} 0794 for count in {1..10}; do echo $count ; done 0795 for f (*(.)) mv $f fixed_$f 0796 for f (**/x) cp newx $f 0797 for f (*.txt) { echo $f } 0798 for f in **/x; do;cp newx $f; done 0799 for f in */include/dbcommon.php; do;cp dbcommon.php $f; done 0800 for file (*(ND-.)) IFS= read -re < $file 0801 for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav} 0802 for i in *(.); mv $i ${i:u} # `bar to `BAR 0803 for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i 0804 for i in **/*.gif; convert $i $i:r.jpg 0805 for i in {3,4}; sed s/flag=2/flag=$i/ fred.txt > fred$i.txt 0806 for ip ({217..219} 225) {echo -n $ip ;ping -n 1 11.2.2.$ip| grep Received} 0807 for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user} 0808 for x ( 1 2 {7..4} a b c {p..n} *.php) {echo $x} 0809 select name in a ; do echo ; done 0810 select name; do echo ; done 0811 if : ; then echo ; elif [[ : ]] ; then echo ; else echo ; fi 0812 if [ $# -gt 0 ];then string=$*;else;string=$(getclip);fi 0813 if [ $# -gt 0 ];then string=$*;else;string=$(getclip);fi # get parameter OR paste buffer 0814 if [[ (($x -lt 8) && ($y -ge 32)) || (($z -gt 32) && ($w -eq 16)) ]] ; then print "complex combinations"; fi 0815 if builtin cd $1 &> /dev/null ; then echo ; fi 0816 if grep -iq 'matching' *.php ;then echo "Found" ;else echo "Not Found"; fim=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") fi 0817 while : || : ; do echo ; done 0818 while (true){echo -n .;sleep 1} 0819 while (true){echo .;sleep 1} 0820 while true ;do date; sleep 5; done # forever 0821 while true; do echo "infinite loop"; sleep 5; done 0822 until : ; : ; do echo ; done 0823 case a in a) esac 0824 case a in a) echo ; esac 0825 case pwd in (patt1) echo ; echo ;; (patt*) echo ;& patt?|patt) echo ;| 0826 patt) echo ;; esac 0827 repeat 1+2+`echo 1`+23 do echo pl; done 0828 repeat 3 time sleep 3 # single command 0829 repeat 5 ;do date; sleep 5; done # multi 0830 foreach x y z ( a `a b`; c ) echo ;end 0831 for x y ( a b bc d ds ) echo $x $y 0832 for x y in a b c ; echo $x $y 0833 for x y ; echo $x $y 0834 case w { a) echo ;& (b?) echo } 0835 case a in 0836 #a) echo ;; 0837 a#) echo ;; 0838 esac 0839 0840 for name in a 0841 b c ; 0842 do 0843 echo 0844 done 0845 0846 case a in 0847 a\( | b*c? ) echo 0848 (b$c) # no pattern 0849 ;; 0850 (b$c) ;; 0851 # no pattern 0852 (b$c) 0853 esac 0854 0855 case "$1" in 0856 "a") run_a|&a;; 0857 "b") run_b;; 0858 "c") run_c;; 0859 *) echo "Plase choose between 'a', 'b' or 'c'" && exit 1;; 0860 esac 0861 0862 case $ans in 0863 1|a) sdba $key;; 0864 2|f) sdbf $key;; 0865 3|i) sdbi $key;; 0866 *) echo "wrong answer $ans\n" ;; 0867 esac 0868 0869 case "$ans" in 0870 2|${prog}9) cd "$(cat /c/aam/${prog}9)" ;; 0871 **) echo "wrong number $ans\n" ;; 0872 esac 0873 0874 select f in $(ls **/*.tex |egrep -i "${param}[^/]*.tex") 0875 do 0876 if [[ "$REPLY" = q ]] 0877 then 0878 break 0879 elif [[ -n "$f" ]]; then 0880 gvim $f 0881 fi 0882 done 0883 0884 for d (. ./**/*(N/m-2)) { 0885 print -r -- $'\n'${d}: 0886 cd $d && { 0887 l=(*(Nm-2)) 0888 (($#l)) && ls -ltd -- $l 0889 cd ~- 0890 } 0891 } 0892 0893 for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do 0894 lynx -source $f >${f:t} 0895 done 0896 0897 for f in ./**/*(-@); do 0898 stat +link -A l $f 0899 (cd $f:h & [[ -e $l.gz ]]) & ln -sf $l.gz $f 0900 done 0901 0902 for ((i=1; i <= $#fpath; ++i)); do 0903 dir=$fpath[i] 0904 zwc=${dir:t}.zwc 0905 if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then 0906 continue 0907 fi 0908 files=($dir/*(N-.)) 0909 if [[ -w $dir:h && -n $files ]]; then 0910 files=(${${(M)files%/*/*}#/}) 0911 if ( cd $dir:h && 0912 zrecompile -p -U -z $zwc $files ); then 0913 fpath[i]=$fpath[i].zwc 0914 fi 0915 fi 0916 done 0917 0918 if ztcp pwspc 2811; then 0919 tcpfd=$REPLY 0920 handler() { 0921 zle -I 0922 local line 0923 if ! read -r line <&$1; then 0924 # select marks this fd if we reach EOF, 0925 # so handle this specially. 0926 print "[Read on fd $1 failed, removing.]" >&2 0927 zle -F $1 0928 return 1 0929 fi 0930 print -r - $line 0931 } 0932 zle -F $tcpfd handler 0933 fi 0934 0935 while [[ $? -eq 0 ]] do 0936 b=($=ZPCRE_OP) 0937 accum+=$MATCH 0938 pcre_match -b -n $b[2] -- $string 0939 done 0940 0941 # bug #380229 0942 ${str:$((${#a[1]}+1))} 0943 0944 # from http://zshwiki.org/home/examples/hardstatus 0945 function title { 0946 if [[ $TERM == "screen" ]]; then 0947 # Use these two for GNU Screen: 0948 print -nR $'\033k'$1$'\033'\\ 0949 0950 print -nR $'\033]0;'$2$'\a' 0951 elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then 0952 # Use this one instead for XTerms: 0953 print -nR $'\033]0;'$*$'\a' 0954 fi 0955 } 0956 0957 function precmd { 0958 title zsh "$PWD" 0959 } 0960 0961 function preexec { 0962 emulate -L zsh 0963 local -a cmd; cmd=(${(z)1}) 0964 title $cmd[1]:t "$cmd[2,-1]" 0965 } 0966 0967 function ddump(){diff -w ~dump/"$1" "$1"} # diff local file with new one in dump 0968 function g{0..9} { gmark $0 $* } # declaring multiple functions 0969 function hello_function { echo "hello world" ; zle .accept-line} 0970 function scd(){setopt nonomatch;e=/dev/null;cd $1(/) &> $e||cd $1*(/) &> $e||cd *$1(/) &> $e||cd *${1}*(/) &> $e||echo sorry} 0971 function vx{0..9} {gvim.exe c:/aax/${0/#v/} &} 0972 function {xyt,xyy} { if [ "$0" = "xyy" ]; then echo run xyy code; else echo run xyt code; fi ; echo run common code } # 0973 0974 # creating a family of functions 0975 # generate hrefs from url 0976 function href{,s} 0977 { 0978 # href creates an HTML hyperlink from a URL 0979 # hrefs creates an HTML hyperlink from a URL with modified anchor text 0980 PROGNAME=`basename $0` 0981 url=`cat /dev/clipboard` 0982 if [ "$PROGNAME" = "href" ] ; then 0983 href="<a href='$url'>$url" 0984 elif [ "$PROGNAME" = "hrefs" ] ; then 0985 anchortext=${${(C)url//[_-]/ }:t} 0986 href="<a href='$url'>$anchortext" 0987 fi 0988 echo -n $col 0989 echo $href > /dev/clipboard | more 0990 } 0991 0992 # create vim scratch files va,vb to vz 0993 function vx{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,q,r,s,t,u,v,w,x,y,z} 0994 { 0995 scratchfile=${0/#v/} 0996 gvim.exe c:/aax/$scratchfile & 0997 } 0998 0999 VDF(){cd *(/om[1]);F=$(echo *(.om[1]));vi $F} 1000 cyg(){reply=("$(cygpath -m $REPLY)")} 1001 f (){for i; do echo $i;done} 1002 fg_light_red=$'%{\e[1;31m%}' 1003 fn() { setopt localtraps; trap '' INT; sleep 3; } 1004 nt() { [[ $REPLY -nt $NTREF ]] } 1005 preexec(){ echo using $@[1]} 1006 take(){[ $# -eq 1 ] && mkdir "$1" && cd "$1"} # create a directory and move to it in one go 1007 1008 caption always "%3n %t%? (%u)%?%?: %h%?" 1009 1010 preexec() { 1011 emulate -L zsh 1012 local -a cmd; cmd=(${(z)1}) # Re-parse the command line 1013 1014 # Construct a command that will output the desired job number. 1015 case $cmd[1] in 1016 fg) 1017 if (( $#cmd == 1 )); then 1018 # No arguments, must find the current job 1019 cmd=(builtin jobs -l %+) 1020 else 1021 # Replace the command name, ignore extra args. 1022 cmd=(builtin jobs -l ${(Q)cmd[2]}) 1023 fi;; 1024 %*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above 1025 exec) shift cmd;& # If the command is 'exec', drop that, because 1026 # we'd rather just see the command that is being 1027 # exec'd. Note the ;& to fall through. 1028 *) title $cmd[1]:t "$cmd[2,-1]" # Not resuming a job, 1029 return;; # so we're all done 1030 esac 1031 1032 local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell 1033 1034 # Run the command, read its output, and look up the jobtext. 1035 # Could parse $rest here, but $jobtexts (via $jt) is easier. 1036 $cmd >>(read num rest 1037 cmd=(${(z)${(e):-\$jt$num}}) 1038 title $cmd[1]:t "$cmd[2,-1]") 2>/dev/null 1039 } 1040 1041 function precmd() { 1042 title zsh "$IDENTITY:$(print -P %~)" 1043 } 1044 1045 "%{^[]0;screen ^En (^Et) ^G%}" 1046 1047 print -nRP $'\033k%(!.#\[.)'$1$'%'$\(\(20\-${#1}\)\)$'< ..<'${${2:+${${${@[${#${@}}]##/*/}/#/ }:-}}//\"/}$'%(!.\].)\033'\\ 1048 1049 c() { echo -E "$(<$1)" } 1050 col() { for l in ${(f)"$(<$1)"} ; echo ${${(Az)l}[$2]} } 1051 colx() { for l in ${(f)"$(eval ${(q)@[2,$]})"} ; echo ${${(Az)l}[$1]} } 1052 1053 [[ -r /etc/ssh/ssh_known_hosts ]] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _global_ssh_hosts=() 1054 _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=() 1055 _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=() 1056 : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=() 1057 1058 prefix='(I:'$@[$(($i+1))]':)'$prefix || prefix='${('$tmp'I:'$@[$(($i+1))]':'${prefix[$(($#tmp+4)),-1]} 1059 prefix='${'${j:+($j)}$prefix; suffix+=':#'${@[$(($i+1))]//(#m)[\/\'\"]/\\$MATCH}'}' 1060 cmd+='<'${(q)@[$(($i+1))]}';' 1061 C=${OPTARG//(#m)[[\/\'\"\\]/\\$MATCH} 1062 $=p $e'"$(<'${(j:<:)${(q)@}}')"'$m 1063 1064 zshaddhistory() { 1065 print -sr -- ${1%%$'\n'} 1066 fc -p .zsh_local_history 1067 } 1068 1069 TRAPINT() { 1070 print "Caught SIGINT, aborting." 1071 return $(( 128 + $1 )) 1072 } 1073 1074 zsh_directory_name() { 1075 emulate -L zsh 1076 setopt extendedglob 1077 local -a match mbegin mend 1078 if [[ $1 = d ]]; then 1079 # turn the directory into a name 1080 if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then 1081 typeset -ga reply 1082 reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) ) 1083 else 1084 return 1 1085 fi 1086 elif [[ $1 = n ]]; then 1087 # turn the name into a directory 1088 [[ $2 != (#b)p:(?*) ]] && return 1 1089 typeset -ga reply 1090 reply=(/home/pws/perforce/$match[1]) 1091 elif [[ $1 = c ]]; then 1092 # complete names 1093 local expl 1094 local -a dirs 1095 dirs=(/home/pws/perforce/*(/:t)) 1096 dirs=(p:${^dirs}) 1097 _wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs 1098 return 1099 else 1100 return 1 1101 fi 1102 return 0 1103 } 1104 1105 () { 1106 print File $1: 1107 cat $1 1108 } =(print This be the verse) 1109 1110 if [[ $foo = (a|an)_(#b)(*) ]]; then 1111 print ${foo[$mbegin[1],$mend[1]]} 1112 fi 1113 1114 zshaddhistory() { 1115 emulate -L zsh 1116 ## uncomment if HISTORY_IGNORE 1117 ## should use EXTENDED_GLOB syntax 1118 # setopt extendedglob 1119 [[ $1 != ${~HISTORY_IGNORE} ]] 1120 } 1121 1122 pick-recent-dirs-file() { 1123 if [[ $PWD = ~/text/writing(|/*) ]]; then 1124 reply=(~/.chpwd-recent-dirs-writing) 1125 else 1126 reply=(+) 1127 fi 1128 } 1129 1130 run-help-ssh() { 1131 emulate -LR zsh 1132 local -a args 1133 # Delete the "-l username" option 1134 zparseopts -D -E -a args l: 1135 # Delete other options, leaving: host command 1136 args=(${@:#-*}) 1137 if [[ ${#args} -lt 2 ]]; then 1138 man ssh 1139 else 1140 run-help $args[2] 1141 fi 1142 } 1143 1144 local -A zdn_top=( 1145 g ~/git 1146 ga ~/alternate/git 1147 gs /scratch/$USER/git/:second2 1148 :default: /:second1 1149 ) 1150 1151 (( $#files > 0 )) && print -rl -- $files | \ 1152 mailx -s "empty files" foo [at] bar.tdl 1153 1154 print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \ 1155 ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]} 1156 1157 paste <(cut -f1 file1) <(cut -f3 file2) | 1158 tee >(process1) >(process2) >/dev/null 1159 1160 ls \ 1161 > x* 1162 1163 sed ' 1164 s/mvoe/move/g 1165 s/thier/their/g' myfile 1166 1167 1168 trap ' 1169 # code 1170 ' NAL 1171 1172 !! # previous command 1173 !!:0 !^ !:2 !$ !#$ !#:2 !#1 !#0 1174 !!:gs/fred/joe/ # edit previous command replace all fred by joe 1175 !!:gs/fred/joe/ # edit previous command replace all fred by joe 1176 !!:s/fred/joe/ # Note : sadly no regexp available with :s/// 1177 !!:s/fred/joe/ # edit previous command replace first fred by joe 1178 !$ (last argument of previous command) 1179 !$:h (last argument, strip one level) 1180 !$:h:h (last argument, strip two levels) 1181 !-2 # command before last 1182 !1 # oldest command in your history 1183 !42 # Re-execute history command 42 1184 !42:p 1185 !?echo 1186 !?saket?:s/somefile1/somefile2/ 1187 1188 (($#l)) && ls -ltd -- $l 1189 ((val2 = val1 * 2)) 1190 (mycmd =(myoutput)) &! 1191 : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'}) 1192 : > /apache/access.log # truncate a log file 1193 < readme.txt 1194 A=(1 2 5 6 7 9) # pre-populate an array 1195 C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico /bin/zsh --login 1196 C=3 && F=$(print *(.om[1,$C])) && for f ($(print $F)){php -l $f} && scp -rp $(print $F) user@192.168.1.1:$PWD 1197 EDITOR='/bin/vim' 1198 FILE=$(echo *(.om[1])) && ls -l $FILE && ssh 192.168.1.1 -l root "zsh -c 'ls -l $PWD/$FILE'" 1199 FILES=( .../files/* ) 1200 IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}} 1201 IPREFIX=${PREFIX%%\=*}= 1202 PREFIX=${PREFIX#*=} 1203 PROMPT3="Choose File : " 1204 PROMPT="%{$bg[cyan]%}%% " 1205 PS3="$fg_light_red Select file : " 1206 REPORTTIME=10 # Automatically /Report CPU usage for commands running longer than 10 seconds 1207 RPROMPT="[%t]" (display the time) 1208 X=(x1 x2) 1209 Y=(+ -) 1210 [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t 1211 [[ $OSTYPE == (#i)LINUX*(#I) ]]; 1212 [[ 'cell=456' =~ '(cell)=(\d+)' ]] && echo $match[1,2] $MATCH 1213 [[ -e $L/config.php ]] && cp -p -update $T/config.php $L 1214 [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char 1215 [[ 1 = 0 ]] && echo eq || echo neq 1216 [[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] && 1217 ^chim^&-&ney-&-&-cheree # reuse LHS 1218 ^fred^joe # edit previous command replace fred by joe 1219 ^php^cfm # modify previous command (good for correcting spellos) 1220 ^str1^str2^:G # replace as many as possible 1221 ^str1^str2^:u:p # replace str1 by str2 change case and just display 1222 a=(**/*(.D));echo $#a # count files in a (huge) hierarchy 1223 a=(1 2 3 4); b=(a b); print ${a:^b} 1224 a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}" 1225 a=12345 1226 aa[(e)*]=star 1227 accum=() 1228 alias '..'='cd ..' 1229 alias -g ...='../..' 1230 alias -g NF='*(.om[1])' # newest file 1231 alias gcd="cd $MCD" # double quote stops once only evaluation 1232 alias mcd="MCD=$(pwd)" # double quote stops once only evaluation 1233 anchortext=${${(C)url//[_-]/ }:t} # titlecase 1234 arr=(veldt jynx grimps waqf zho buck) 1235 array=(~/.zshenv ~/.zshrc ~/.zlogout) 1236 autoload edit-command-line 1237 autoload -Uz up-line-or-beginning-search 1238 autoload colors ; colors 1239 bindkey "^N" most-recent-file 1240 bindkey -s "^[OS" "\^d\^c\n" 1241 bindkey -s "^[[18~" "ls -l\n" 1242 c=(*.c) o=(*.o(N)) eval 'ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}' 1243 cd !$:h 1244 cd !?ls 1245 diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort) 1246 dpath=${upath/#\/c\//c:/} # convert /c/path/ to c:\path\ 1247 drive=$([[ "$LOGNAME" != davidr ]] && echo '/o' || echo '/c') # trad way 1248 drive=${${${LOGNAME:#davidr}:+/o}:-/c} # zsh way 1249 egrep -i "^ *mail\(" **/*.php 1250 eval "$1=$PWD" 1251 eval "m=($(cat -- $nameoffile)" 1252 feh $FILES[$RANDOM%$#FILES+1] 1253 foo="twinkle twinkle little star" sub="t*e" rep="spy" 1254 foo=$'bar\n\nbaz\n' 1255 foo=fred-goat-dog.jpg 1256 fred=$((6**2 + 6)) # can do maths 1257 (( $# == 0 )); 1258 [ "$p1" = "end" ] || [ "$p1" = "-e" ] 1259 [ $# -gt 0 ] # parameter cnt > 0 (arguments) 1260 [ $cnt -eq 1 ] 1261 [[ "$1" == [0-9] ]] # if $1 is a digit 1262 [[ "$p2" == *[a-zA-Z][a-zA-Z][a-zA-Z]* ]] # contains at least 3 letters 1263 [[ "$pwd" == *$site2* ]] 1264 [[ "$url" = www* ]] # begins with www 1265 [[ -e /c/aam/z$1 ]] # file exists 1266 p1 p2 p3 1267 pcre_compile -m "\d{5}" 1268 pcre_match -b -- $string 1269 perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > $(print NF).txt 1270 ps -p $$ | grep $$ | awk '{print $NF}' 1271 r oldstr=newstr 1272 r\m $(locate nohup.out) 1273 read -r line <&$fd; print -r - $line 1274 read ans ; # read in a parameter 1275 setopt EXTENDED_GLOB # lots of clever stuff requires this 1276 source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE 1277 ssh -t root@192.18.001.001 'sh -c "cd /tmp && exec zsh -l"' 1278 ssh 192.168.1.218 -l root "zsh -c 'for i (/usr/*(/)) {ls \$i }'" 1279 sshpass -p myppassword scp -rp * user@18.128.158.158:${PWD/staging/release} 1280 str=aa,bb,cc;print ${(j:,:)${(qq)${(s:,:)str}}} # quotify a string 1281 tel blenkinsop | grep -o "[[:alnum:][:graph:]]*@[[:alnum:][:graph:]]*" # filter just an email address from a text stream (not zsh) 1282 touch {t,p}{01..99}.{php,html,c} # generate 600 test files 1283 touch {y,y2}.cfm 1284 trap - INT 1285 typeset "aa[one\"two\"three\"quotes]"=QQQ 1286 typeset -A aa 1287 typeset -A ass_array; ass_array=(one 1 two 2 three 3 four 4) 1288 typeset -A convtable 1289 typeset -i 16 y 1290 unsetopt XTRACE VERBOSE 1291 unsetopt localtraps 1292 upath=${wpath//\\/\/} # convert backslashes to forward slashes (Dos to Unix 1293 url='www.some.com/some_strIng-HERe' 1294 val=a:b:c 1295 var=133;if [[ "$var" = <-> ]] ; then echo "$var is numeric" ;fi 1296 var=ddddd; [[ "$var" =~ ^d+$ ]] && echo matched || echo did not match 1297 var=dddee; regexp="^e+$"; [[ "$var" =~ $regexp ]] && echo $regexp matched $var || echo $regexp did not match $var 1298 vared -p "choose 1-3 : " -c ans 1299 vared PATH 1300 whence -vsa ${(k)commands[(I)zsh*]} # search for zsh* 1301 widget 1302 wpath=${wpath//\//\\\\} # substitute Unix / with dos \ slashes 1303 x=$? 1304 zmodload -F zsh/stat b:zstat 1305 zsh -lxic : 2> >(grep "> alias 'web'") 1306 { paste <(cut -f1 file1) <(cut -f3 file2) } > >(process)