File indexing completed on 2024-05-12 04:02:11
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 cat <<heredoc 0470 bla bla 0471 heredoc 0472 cat <<heredoc -a 0473 bla bla 0474 heredoc 0475 r=$(xxx $@ 2>&1) 0476 0477 # branches 0478 cat a|cat 0479 cat a&cat 0480 cat a||cat 0481 cat a&&cat 0482 cat a;cat 0483 cat a | cat 0484 cat a & cat 0485 cat a || cat 0486 cat a && cat 0487 cat a ; cat 0488 cat a'a';cat 0489 0490 # substitutions 0491 echo '' 'a' '\' "" "a" "\\" "$a" "a""a"'a''a' a'b'c a"b"c a$'\n'c 0492 echo a!bc a{a}b a{b,c}d a{b,{d,e}}d a\ b 0493 echo a$bc a$b/c a${b}c a$((b-3))c a$(b)c a$(a b c)c 0494 echo ${a[*]} ${a[@]} ${a[${b}]} ${a:-x$z} ${a/g} ${a//f/f} ${a//f*/f*} 0495 echo ${!} ${!a} ${#a[1]} ${a:1:$b} $((++i,i--)) 0496 echo ${a:^v} ${=a:/#%a#?*/bla} ${x#??(#i)} ${das:-{}<a.zsh} 0497 echo ${(f)"$(<$1)"} ${${(Az)l}[$2]} ${(f)"$(eval ${(q)@[2,$]})"} 0498 echo ${(@)foo} ${(@)foo[1,2]} ${${(A)name}[1]} ${(AA)=name=...} ${(Q)${(z)foo}} 0499 echo ${(ps.$sep.)val} ${(ps.${sep}.)val} ${(s.$sep.)val} ${(s.)(.)val} 0500 echo ${(pr:2+3::_::$d:)var} ${(r:2+3::_::$d:)var} 0501 echo ${${:-=cat}:h} 0502 $foo:h34:a:gs/dfs/fds/:s/fds/d'd'f xyz $foo: $foo:O $foo:A 0503 3=$foo:QQQ xyz $a[3,$]:h3:t1:e 0504 echo ${${~foo}//\*/*.c} 0505 echo !$ !!:$ !* !!:* !-2:2 !:-3 !:2* !:2- !:2-3 !^ !:1 !!:1 0506 echo "$bg[blue]$fg[yellow]highlight a message" 0507 echo "$bg[red]$fg[black]${(l:42::-:)}" 0508 echo "${${(@)foo[2,4]}[2]}" 0509 echo "${(j::)${(@Oa)${(s::):-hello}}}" 0510 echo "${(j::)${(@Oa)${(s::):-hello}}}" 0511 echo "<a href='$url'>$anchortext</a>" 0512 echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 )) 0513 echo $a[${RANDOM}%1000] $a[${RANDOM}%11+10] 0514 echo $convtable[158] 0515 echo ${array[0]: -7 : + 22 } ${array[1]: num } 0516 echo ${parameter##word} ${parameter%%word} 0517 echo $f ' # $fred' 0518 echo $f:e $f:h $f:h:h $f:r $f:t $f:t:r $file:r 0519 echo ${(C)foo:gs/-/ /:r} ${(M)0%%<->} ${(j/x/s/x/)foo} ${(l:$COLUMNS::-:)} 0520 echo ${(l:3::0:)${RANDOM}} ${(s/x/)foo%%1*} ${0##*[!0-9]} 0521 echo ${a:2:2} ${a:2} ${a[1,3]} ${d/#?/} ${d/%?/} ${d[1,-2]} ${d[2,$]} 0522 echo ${d[2,-1]} ${file##*/} ${file%.*} ${texfilepath%/*.*} *(f:u+rx,o-x:) 0523 echo *(f:u+rx:) **/*(@-^./=%p) **/*(@-^./=%p) convert_csv.php(:a) 0524 cd $(locate -l1 -r "/zoo.txt$")(:h) # cd to directory of first occurence of a file zoo.txt 0525 cd ${$(!!)[3]:h} # cd to 3rd in list 0526 cd ${$(locate zoo.txt)[1]:h} 0527 cd ${drive}/inetpub/wwwdev/www.some.co.uk/ 0528 cd **/*.php(.om[1]:h) # cd to directory of newest php file 0529 cd - 0530 cd /tmp/test/;touch {1..5} {6,7,8,12} {00..03} 0531 cd ~www/admin 0532 chmod g+w **/* 0533 chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:) 0534 cp *.mp3(mh-4) /tmp # copy files less than 4 hours old 0535 cp -a file1 file # -a transfer permissions etc of file1 to file2preserve 0536 file **/*(D@) | fgrep broken 0537 file **/*(D@) | fgrep broken 0538 file=${1/#\//C:\/} # substitute / with c:/ Beginning of string 0539 file=${1/%\//C:\/} # substitute / with c:/ End of string 0540 file=${1/\//C:\/} # substitute / with c:/ ANYWHERE in string 0541 filelst+=($x) 0542 filelst[$(($#filelst+1))]=$x 0543 files=(${(f)"$(egrepcmd1l)"} ) 0544 files=(${(f)"$(ls *$**)"}(.N)) # ")` 0545 files=(**/*(ND.L0m+0m-2)) 0546 mkdir $f:h;touch $f 0547 mv Licence\ to\ Print\ Money.pdf !#^:gs/\\ // 0548 path=(${path:#$path_to_remove}) 0549 path=(${path:|excl}) 0550 pattern=${(b)str} 0551 pattern=${(q)str} 0552 print "$aa[one\"two\"three\"quotes]" 0553 print "$bg[cyan]$fg[blue]Welcome to man zsh-lovers" >> $TTY 0554 print $(( [#8] x = 32, y = 32 )) 0555 print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or 0556 print $(history -n -1|sed 's/.* //') 0557 print $aa[(e)*] 0558 print $ass_array[one] 0559 print $x $y 0560 print ${#path[1]} # length of first element in path array 0561 print ${#path} # length of "path" array 0562 print ${$( date )[2,4]} # Print words two to four of output of ’date’: 0563 print ${$(/sbin/ifconfig tun0)[6]} 0564 print ${${$( LC_ALL=C /sbin/ifconfig lo )[6]}#addr:} 0565 print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://} 0566 print ${${(Cs:-:):-fred-goat-dog.jpg}%.*} 0567 print ${${(z)$(history -n -1)}[-1]} 0568 print ${${(z)history[$((HISTCMD-1))]}[-1]} 0569 print ${(L)s// /-}.jpg 0570 print ${(L)s:gs/ /-/}.jpg 0571 print ${(S)foo//${~sub}/$rep} 0572 print ${(k)ass_array} # prints keys 0573 print ${(v)ass_array} # prints values 0574 print ${JUNK/%./_} # substitute last . for a _ 0575 print ${JUNK/.(#e)/_} # substitute last . for a _ 0576 print ${arr//(#m)[aeiou]/${(U)MATCH}} 0577 print ${array:t} 0578 print ${foo%%$'\n'} # strip out a trailing carriage return 0579 print ${foo//$'\n'} # strip out any carriage returns (some systems use \r) 0580 print ${foo//${~sub}/$rep} 0581 print ${foo: 1 + 2} 0582 print ${foo:$(( 1 + 2))} 0583 print ${foo:$(echo 1 + 2)} 0584 print ${foo:3} 0585 print ${param:&} (last substitute) 0586 print ${somevar//[^[:alnum:]]/_} # replace all non-alphanumerics with _ the // indicates global substitution 0587 print ${string[(r)d?,(r)h?]} 0588 print '\e[1;34m fred' 0589 print (*/)#zsh_us.ps 0590 print *(e:age 2006/10/04 2006/10/09:) 0591 print **/*(/^F) | xargs -n1 -t rmdir #delete empty directories 0592 print *.c(e_'[[ ! -e $REPLY:r.o ]]'_) 0593 print -C 1 $X # print each array element on it's own line 0594 print -l "${(s.:.)line}" 0595 print -l $MATCH X $match 0596 print -l $accum 0597 print -l *(n:t) # order by name strip directory 0598 print -l **/*(-@) 0599 print -l **/*(On:t) # recursive reverse order by name, strip directory 0600 print -r -- $^X.$^Y 0601 print -r -- ${(qq)m} > $nameoffile # save it 0602 print -rC1 /tmp/foo*(u0^@:t) 0603 print -rC1 b*.pro(#q:s/pro/shmo/)(#q.:s/builtin/shmiltin/) 0604 print -rC2 -- ${1:[...]}/*(D:t) 0605 print -rl $HOME/${(l:20::?:)~:-}* 0606 print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*} 0607 print -rl /**/*~^*/path(|/*) 0608 print {$((##n))..$((##y))}P\ 10P | dc 0609 print root@192.168.168.157:${PWD/test/live}v 0610 0611 0612 # conditions 0613 [ a ] 0614 [ -f f'f'f ] 0615 [ -f f]'f'f] ] 0616 [ -t 13 ] 0617 [ -t 13] ] 0618 [ -t 13] ] 0619 [ -v abc ] 0620 [ -z abc ] 0621 [ abc -ef abc ] 0622 [ abc -ef abc ] 0623 [ abc-ef -ef abc-ef ] 0624 [ abc == abc ] 0625 [ abc < abc ] 0626 [ abc -eq abc ] 0627 [[ abc -eq abc ]] 0628 [ 1+2 -eq 1+2 ] 0629 [[ 1+2 -eq 1+2 ]] 0630 [ a = b c ] 0631 [ -z 1 -a 1 -eq 1 ] 0632 [ 2 -eq 1 -o 1 -eq 1 ] 0633 ( [ a = b ] ) 0634 ([ a = b ]) 0635 [[ a = b c ]] 0636 [[ x =~ a(b c|$)' '{1,}[a[.digit.]] ]] 0637 [[ x =~ [ ] ]] 0638 [[ x =~ ([ ]) ]] 0639 [[ x =~ [ ]] 0640 [[ x =~ ([) ]] 0641 [[ (a =~ a) ]] 0642 [[ (a =~ 0643 a) ]] 0644 [[ a =~ a || a -eq 2 ]] 0645 [[ (a =~ a) || a -eq 2 ]] 0646 [[ a<b ]] 0647 [[ a <b ]] 0648 [[ a< b ]] 0649 [[ a < b ]] 0650 [[(! -d .)]] 0651 [[ ! -d . ]] 0652 [[ !(-d .) ]] 0653 [[ -f a || -f b ]] 0654 [[ -f a||-f b ]] 0655 [[ ! (a -eq b) ]] 0656 [ -d `echo .`] ] 0657 [[ -d `echo .`]] ]] 0658 [[ a != b && ${a}a = b${b} ]] 0659 [[ 0660 1 -eq 2 0661 ]] 0662 [[ 0663 1 0664 -eq 0665 2 0666 ]] 0667 [[ -""(#i)* == $x ]] 0668 [[ ]] 0669 [[ -f ]] 0670 [[ -f <0-99> ]] 0671 [[ $1 == <-> ]] 0672 [[ ?*<0-99> = <0-99> ]] 0673 [[ -f = ?*<0-99> ]] 0674 [[ a/sa[s = dsad?*<0-9>dsa$ds ]] 0675 [[ a/sa[s = dsad?*<0-9>ds/a$ds ]] 0676 [[ a =~ <1-2>a<->a<-2>a<2->a([!d]a?s[x[:alnum:]]|d?)p ]] 0677 [[ -n file*(#qN) ]] 0678 [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists. 0679 [[ $str = ${~pattern} ]] 0680 [[ $str = ${~pattern} ]] 0681 [[ "?" = ${(~j.|.)array} ]] 0682 ( [[ a = b ]] ) 0683 ([[ a = b ]]) 0684 0685 [[ #comm1 0686 #comm2 0687 ! #comm3 0688 p[1] #comm4 0689 == #comm5 0690 p[2] #comm6 0691 #comm7 0692 #comm8 0693 ]] 0694 0695 [[ #comm1 0696 #comm2 0697 -f #comme3 0698 #comm4 0699 p[2] #comm5 0700 #comm6 0701 #comm7 0702 ]] 0703 0704 [ a -eq 2 ] || [ a -eq 2] ] && [[ a -eq 2 ]] || [[ a != b ]]; 0705 [ a -eq 2 ]||[ a -eq 2] ]&&[[ a -eq 2 ]]||[[ a != b ]]; 0706 0707 ((3+1+a+$c*(x) & 0x4342_2fd+03-08_5/23#D9a@_^8)) 0708 ((1.3/(2-(a-4)))) 0709 0710 # they are not arithmetic evaluations... 0711 ((cmd && cmd) || cmd) 0712 $((cmd && cmd) || cmd) 0713 ((cmd && 0714 cmd) || cmd) 0715 $((cmd && 0716 cmd) || cmd) 0717 0718 print $(( [#_] sqrt(1e7) 0__39 1423e23 .2443 43.34 34.43e4 .d)) 0719 0720 { echo 0721 echo 0722 } 0723 { echo ; } 0724 { echo } 0725 {echo} 0726 {ls f} always {ls} 0727 {echo {a}} 0728 }echo 0729 echo {a} {a/b} a{b}/c a/b{c} a/{b} a/{b}c d/{{a}} 0730 echo {a{a{a}}} 0731 echo {a{a{a}a}a}a 0732 echo {a 0733 echo a} 0734 echo{a} 0735 echo{a{a{a}}} 0736 echo{a{a{a}a}a}a 0737 echo{a 0738 echo} 0739 0740 { {echo a} } 0741 { {echo a}a} } 0742 { { echo a } } 0743 { { echo a}a } } 0744 0745 { {echo a/b} } 0746 { {echo a/b}a} } 0747 { { echo a/b } } 0748 { { echo a/b}a } } 0749 0750 { {echo >a/b} } 0751 { {echo >a/b}a} } 0752 { { echo >a/b } } 0753 { { echo >a/b}a } } 0754 0755 {ab}c} 0756 {a,b}c} 0757 {ab}[} 0758 {a,b}[} 0759 0760 cat >f{oo,ar} 0761 0762 (echo ; echo) 0763 (echo 0764 echo) 0765 (echo a) 0766 test a -eq b 0767 0768 # functions 0769 a() { echo x; } 0770 a () { echo x; } 0771 function f { echo x; } 0772 kde.org() { echo x; } 0773 --func() { echo x; } 0774 noglob function f { echo x; } 0775 0776 # variables 0777 a=(a b c) 0778 a='a' 0779 a+=b 0780 a[1]='a' 0781 a[$i]='x' 0782 a[$(( 0783 2+4 0784 ))]='x' 0785 a=([a]=2 `echo` -s > 'ds') 0786 a=(#comment 0787 value#nocomment #comment) 0788 ) 0789 a=a cat 0790 a=`ls` cat 0791 a[2+3][d]=5 0792 0793 # control structure 0794 for name in a b c {d,e} ; do echo ; done 0795 for name; do echo ; done 0796 for name do echo ; done 0797 for ((i=0;i<5;++i)) ; do echo $i ; done 0798 for ((i=1;$#A[i];i++)) echo $A[$i] 0799 for c ({1..50}) {php ./test.php; sleep 5;} 0800 for count in {1..10}; do echo $count ; done 0801 for f (*(.)) mv $f fixed_$f 0802 for f (**/x) cp newx $f 0803 for f (*.txt) { echo $f } 0804 for f in **/x; do;cp newx $f; done 0805 for f in */include/dbcommon.php; do;cp dbcommon.php $f; done 0806 for file (*(ND-.)) IFS= read -re < $file 0807 for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav} 0808 for i in *(.); mv $i ${i:u} # `bar to `BAR 0809 for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i 0810 for i in **/*.gif; convert $i $i:r.jpg 0811 for i in {3,4}; sed s/flag=2/flag=$i/ fred.txt > fred$i.txt 0812 for ip ({217..219} 225) {echo -n $ip ;ping -n 1 11.2.2.$ip| grep Received} 0813 for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user} 0814 for x ( 1 2 {7..4} a b c {p..n} *.php) {echo $x} 0815 select name in a ; do echo ; done 0816 select name; do echo ; done 0817 if : ; then echo ; elif [[ : ]] ; then echo ; else echo ; fi 0818 if [ $# -gt 0 ];then string=$*;else;string=$(getclip);fi 0819 if [ $# -gt 0 ];then string=$*;else;string=$(getclip);fi # get parameter OR paste buffer 0820 if [[ (($x -lt 8) && ($y -ge 32)) || (($z -gt 32) && ($w -eq 16)) ]] ; then print "complex combinations"; fi 0821 if builtin cd $1 &> /dev/null ; then echo ; fi 0822 if grep -iq 'matching' *.php ;then echo "Found" ;else echo "Not Found"; fim=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") fi 0823 while : || : ; do echo ; done 0824 while (true){echo -n .;sleep 1} 0825 while (true){echo .;sleep 1} 0826 while true ;do date; sleep 5; done # forever 0827 while true; do echo "infinite loop"; sleep 5; done 0828 until : ; : ; do echo ; done 0829 case a in a) esac 0830 case a in a) echo ; esac 0831 case pwd in (patt1) echo ; echo ;; (patt*) echo ;& patt?|patt) echo ;| 0832 patt) echo ;; esac 0833 repeat 1+2+`echo 1`+23 do echo pl; done 0834 repeat 3 time sleep 3 # single command 0835 repeat 5 ;do date; sleep 5; done # multi 0836 foreach x y z ( a `a b`; c ) echo ;end 0837 for x y ( a b bc d ds ) echo $x $y 0838 for x y in a b c ; echo $x $y 0839 for x y ; echo $x $y 0840 case w { a) echo ;& (b?) echo } 0841 case a in 0842 #a) echo ;; 0843 a#) echo ;; 0844 esac 0845 0846 for name in a 0847 b c ; 0848 do 0849 echo 0850 done 0851 0852 case a in 0853 a\( | b*c? ) echo 0854 (b$c) # no pattern 0855 ;; 0856 (b$c) ;; 0857 # no pattern 0858 (b$c) 0859 esac 0860 0861 case "$1" in 0862 "a") run_a|&a;; 0863 "b") run_b;; 0864 "c") run_c;; 0865 *) echo "Plase choose between 'a', 'b' or 'c'" && exit 1;; 0866 esac 0867 0868 case $ans in 0869 1|a) sdba $key;; 0870 2|f) sdbf $key;; 0871 3|i) sdbi $key;; 0872 *) echo "wrong answer $ans\n" ;; 0873 esac 0874 0875 case "$ans" in 0876 2|${prog}9) cd "$(cat /c/aam/${prog}9)" ;; 0877 **) echo "wrong number $ans\n" ;; 0878 esac 0879 0880 select f in $(ls **/*.tex |egrep -i "${param}[^/]*.tex") 0881 do 0882 if [[ "$REPLY" = q ]] 0883 then 0884 break 0885 elif [[ -n "$f" ]]; then 0886 gvim $f 0887 fi 0888 done 0889 0890 for d (. ./**/*(N/m-2)) { 0891 print -r -- $'\n'${d}: 0892 cd $d && { 0893 l=(*(Nm-2)) 0894 (($#l)) && ls -ltd -- $l 0895 cd ~- 0896 } 0897 } 0898 0899 for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do 0900 lynx -source $f >${f:t} 0901 done 0902 0903 for f in ./**/*(-@); do 0904 stat +link -A l $f 0905 (cd $f:h & [[ -e $l.gz ]]) & ln -sf $l.gz $f 0906 done 0907 0908 for ((i=1; i <= $#fpath; ++i)); do 0909 dir=$fpath[i] 0910 zwc=${dir:t}.zwc 0911 if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then 0912 continue 0913 fi 0914 files=($dir/*(N-.)) 0915 if [[ -w $dir:h && -n $files ]]; then 0916 files=(${${(M)files%/*/*}#/}) 0917 if ( cd $dir:h && 0918 zrecompile -p -U -z $zwc $files ); then 0919 fpath[i]=$fpath[i].zwc 0920 fi 0921 fi 0922 done 0923 0924 if ztcp pwspc 2811; then 0925 tcpfd=$REPLY 0926 handler() { 0927 zle -I 0928 local line 0929 if ! read -r line <&$1; then 0930 # select marks this fd if we reach EOF, 0931 # so handle this specially. 0932 print "[Read on fd $1 failed, removing.]" >&2 0933 zle -F $1 0934 return 1 0935 fi 0936 print -r - $line 0937 } 0938 zle -F $tcpfd handler 0939 fi 0940 0941 while [[ $? -eq 0 ]] do 0942 b=($=ZPCRE_OP) 0943 accum+=$MATCH 0944 pcre_match -b -n $b[2] -- $string 0945 done 0946 0947 # bug #380229 0948 ${str:$((${#a[1]}+1))} 0949 0950 # from http://zshwiki.org/home/examples/hardstatus 0951 function title { 0952 if [[ $TERM == "screen" ]]; then 0953 # Use these two for GNU Screen: 0954 print -nR $'\033k'$1$'\033'\\ 0955 0956 print -nR $'\033]0;'$2$'\a' 0957 elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then 0958 # Use this one instead for XTerms: 0959 print -nR $'\033]0;'$*$'\a' 0960 fi 0961 } 0962 0963 function precmd { 0964 title zsh "$PWD" 0965 } 0966 0967 function preexec { 0968 emulate -L zsh 0969 local -a cmd; cmd=(${(z)1}) 0970 title $cmd[1]:t "$cmd[2,-1]" 0971 } 0972 0973 function ddump(){diff -w ~dump/"$1" "$1"} # diff local file with new one in dump 0974 function g{0..9} { gmark $0 $* } # declaring multiple functions 0975 function hello_function { echo "hello world" ; zle .accept-line} 0976 function scd(){setopt nonomatch;e=/dev/null;cd $1(/) &> $e||cd $1*(/) &> $e||cd *$1(/) &> $e||cd *${1}*(/) &> $e||echo sorry} 0977 function vx{0..9} {gvim.exe c:/aax/${0/#v/} &} 0978 function {xyt,xyy} { if [ "$0" = "xyy" ]; then echo run xyy code; else echo run xyt code; fi ; echo run common code } # 0979 0980 # creating a family of functions 0981 # generate hrefs from url 0982 function href{,s} 0983 { 0984 # href creates an HTML hyperlink from a URL 0985 # hrefs creates an HTML hyperlink from a URL with modified anchor text 0986 PROGNAME=`basename $0` 0987 url=`cat /dev/clipboard` 0988 if [ "$PROGNAME" = "href" ] ; then 0989 href="<a href='$url'>$url" 0990 elif [ "$PROGNAME" = "hrefs" ] ; then 0991 anchortext=${${(C)url//[_-]/ }:t} 0992 href="<a href='$url'>$anchortext" 0993 fi 0994 echo -n $col 0995 echo $href > /dev/clipboard | more 0996 } 0997 0998 # create vim scratch files va,vb to vz 0999 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} 1000 { 1001 scratchfile=${0/#v/} 1002 gvim.exe c:/aax/$scratchfile & 1003 } 1004 1005 VDF(){cd *(/om[1]);F=$(echo *(.om[1]));vi $F} 1006 cyg(){reply=("$(cygpath -m $REPLY)")} 1007 f (){for i; do echo $i;done} 1008 fg_light_red=$'%{\e[1;31m%}' 1009 fn() { setopt localtraps; trap '' INT; sleep 3; } 1010 nt() { [[ $REPLY -nt $NTREF ]] } 1011 preexec(){ echo using $@[1]} 1012 take(){[ $# -eq 1 ] && mkdir "$1" && cd "$1"} # create a directory and move to it in one go 1013 1014 caption always "%3n %t%? (%u)%?%?: %h%?" 1015 1016 preexec() { 1017 emulate -L zsh 1018 local -a cmd; cmd=(${(z)1}) # Re-parse the command line 1019 1020 # Construct a command that will output the desired job number. 1021 case $cmd[1] in 1022 fg) 1023 if (( $#cmd == 1 )); then 1024 # No arguments, must find the current job 1025 cmd=(builtin jobs -l %+) 1026 else 1027 # Replace the command name, ignore extra args. 1028 cmd=(builtin jobs -l ${(Q)cmd[2]}) 1029 fi;; 1030 %*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above 1031 exec) shift cmd;& # If the command is 'exec', drop that, because 1032 # we'd rather just see the command that is being 1033 # exec'd. Note the ;& to fall through. 1034 *) title $cmd[1]:t "$cmd[2,-1]" # Not resuming a job, 1035 return;; # so we're all done 1036 esac 1037 1038 local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell 1039 1040 # Run the command, read its output, and look up the jobtext. 1041 # Could parse $rest here, but $jobtexts (via $jt) is easier. 1042 $cmd >>(read num rest 1043 cmd=(${(z)${(e):-\$jt$num}}) 1044 title $cmd[1]:t "$cmd[2,-1]") 2>/dev/null 1045 } 1046 1047 function precmd() { 1048 title zsh "$IDENTITY:$(print -P %~)" 1049 } 1050 1051 "%{^[]0;screen ^En (^Et) ^G%}" 1052 1053 print -nRP $'\033k%(!.#\[.)'$1$'%'$\(\(20\-${#1}\)\)$'< ..<'${${2:+${${${@[${#${@}}]##/*/}/#/ }:-}}//\"/}$'%(!.\].)\033'\\ 1054 1055 c() { echo -E "$(<$1)" } 1056 col() { for l in ${(f)"$(<$1)"} ; echo ${${(Az)l}[$2]} } 1057 colx() { for l in ${(f)"$(eval ${(q)@[2,$]})"} ; echo ${${(Az)l}[$1]} } 1058 1059 [[ -r /etc/ssh/ssh_known_hosts ]] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _global_ssh_hosts=() 1060 _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=() 1061 _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=() 1062 : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=() 1063 1064 prefix='(I:'$@[$(($i+1))]':)'$prefix || prefix='${('$tmp'I:'$@[$(($i+1))]':'${prefix[$(($#tmp+4)),-1]} 1065 prefix='${'${j:+($j)}$prefix; suffix+=':#'${@[$(($i+1))]//(#m)[\/\'\"]/\\$MATCH}'}' 1066 cmd+='<'${(q)@[$(($i+1))]}';' 1067 C=${OPTARG//(#m)[[\/\'\"\\]/\\$MATCH} 1068 $=p $e'"$(<'${(j:<:)${(q)@}}')"'$m 1069 1070 zshaddhistory() { 1071 print -sr -- ${1%%$'\n'} 1072 fc -p .zsh_local_history 1073 } 1074 1075 TRAPINT() { 1076 print "Caught SIGINT, aborting." 1077 return $(( 128 + $1 )) 1078 } 1079 1080 zsh_directory_name() { 1081 emulate -L zsh 1082 setopt extendedglob 1083 local -a match mbegin mend 1084 if [[ $1 = d ]]; then 1085 # turn the directory into a name 1086 if [[ $2 = (#b)(/home/pws/perforce/)([^/]##)* ]]; then 1087 typeset -ga reply 1088 reply=(p:$match[2] $(( ${#match[1]} + ${#match[2]} )) ) 1089 else 1090 return 1 1091 fi 1092 elif [[ $1 = n ]]; then 1093 # turn the name into a directory 1094 [[ $2 != (#b)p:(?*) ]] && return 1 1095 typeset -ga reply 1096 reply=(/home/pws/perforce/$match[1]) 1097 elif [[ $1 = c ]]; then 1098 # complete names 1099 local expl 1100 local -a dirs 1101 dirs=(/home/pws/perforce/*(/:t)) 1102 dirs=(p:${^dirs}) 1103 _wanted dynamic-dirs expl 'dynamic directory' compadd -S\] -a dirs 1104 return 1105 else 1106 return 1 1107 fi 1108 return 0 1109 } 1110 1111 () { 1112 print File $1: 1113 cat $1 1114 } =(print This be the verse) 1115 1116 if [[ $foo = (a|an)_(#b)(*) ]]; then 1117 print ${foo[$mbegin[1],$mend[1]]} 1118 fi 1119 1120 zshaddhistory() { 1121 emulate -L zsh 1122 ## uncomment if HISTORY_IGNORE 1123 ## should use EXTENDED_GLOB syntax 1124 # setopt extendedglob 1125 [[ $1 != ${~HISTORY_IGNORE} ]] 1126 } 1127 1128 pick-recent-dirs-file() { 1129 if [[ $PWD = ~/text/writing(|/*) ]]; then 1130 reply=(~/.chpwd-recent-dirs-writing) 1131 else 1132 reply=(+) 1133 fi 1134 } 1135 1136 run-help-ssh() { 1137 emulate -LR zsh 1138 local -a args 1139 # Delete the "-l username" option 1140 zparseopts -D -E -a args l: 1141 # Delete other options, leaving: host command 1142 args=(${@:#-*}) 1143 if [[ ${#args} -lt 2 ]]; then 1144 man ssh 1145 else 1146 run-help $args[2] 1147 fi 1148 } 1149 1150 local -A zdn_top=( 1151 g ~/git 1152 ga ~/alternate/git 1153 gs /scratch/$USER/git/:second2 1154 :default: /:second1 1155 ) 1156 1157 (( $#files > 0 )) && print -rl -- $files | \ 1158 mailx -s "empty files" foo [at] bar.tdl 1159 1160 print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \ 1161 ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]} 1162 1163 paste <(cut -f1 file1) <(cut -f3 file2) | 1164 tee >(process1) >(process2) >/dev/null 1165 1166 ls \ 1167 > x* 1168 1169 sed ' 1170 s/mvoe/move/g 1171 s/thier/their/g' myfile 1172 1173 1174 trap ' 1175 # code 1176 ' NAL 1177 1178 !! # previous command 1179 !!:0 !^ !:2 !$ !#$ !#:2 !#1 !#0 1180 !!:gs/fred/joe/ # edit previous command replace all fred by joe 1181 !!:gs/fred/joe/ # edit previous command replace all fred by joe 1182 !!:s/fred/joe/ # Note : sadly no regexp available with :s/// 1183 !!:s/fred/joe/ # edit previous command replace first fred by joe 1184 !$ (last argument of previous command) 1185 !$:h (last argument, strip one level) 1186 !$:h:h (last argument, strip two levels) 1187 !-2 # command before last 1188 !1 # oldest command in your history 1189 !42 # Re-execute history command 42 1190 !42:p 1191 !?echo 1192 !?saket?:s/somefile1/somefile2/ 1193 1194 (($#l)) && ls -ltd -- $l 1195 ((val2 = val1 * 2)) 1196 (mycmd =(myoutput)) &! 1197 : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'}) 1198 : > /apache/access.log # truncate a log file 1199 < readme.txt 1200 A=(1 2 5 6 7 9) # pre-populate an array 1201 C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico /bin/zsh --login 1202 C=3 && F=$(print *(.om[1,$C])) && for f ($(print $F)){php -l $f} && scp -rp $(print $F) user@192.168.1.1:$PWD 1203 EDITOR='/bin/vim' 1204 FILE=$(echo *(.om[1])) && ls -l $FILE && ssh 192.168.1.1 -l root "zsh -c 'ls -l $PWD/$FILE'" 1205 FILES=( .../files/* ) 1206 IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}} 1207 IPREFIX=${PREFIX%%\=*}= 1208 PREFIX=${PREFIX#*=} 1209 PROMPT3="Choose File : " 1210 PROMPT="%{$bg[cyan]%}%% " 1211 PS3="$fg_light_red Select file : " 1212 REPORTTIME=10 # Automatically /Report CPU usage for commands running longer than 10 seconds 1213 RPROMPT="[%t]" (display the time) 1214 X=(x1 x2) 1215 Y=(+ -) 1216 [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t 1217 [[ $OSTYPE == (#i)LINUX*(#I) ]]; 1218 [[ 'cell=456' =~ '(cell)=(\d+)' ]] && echo $match[1,2] $MATCH 1219 [[ -e $L/config.php ]] && cp -p -update $T/config.php $L 1220 [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char 1221 [[ 1 = 0 ]] && echo eq || echo neq 1222 [[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] && 1223 ^chim^&-&ney-&-&-cheree # reuse LHS 1224 ^fred^joe # edit previous command replace fred by joe 1225 ^php^cfm # modify previous command (good for correcting spellos) 1226 ^str1^str2^:G # replace as many as possible 1227 ^str1^str2^:u:p # replace str1 by str2 change case and just display 1228 a=(**/*(.D));echo $#a # count files in a (huge) hierarchy 1229 a=(1 2 3 4); b=(a b); print ${a:^b} 1230 a=(a b); b=(1 2); print -l "${a:^b}"; print -l "${${a:^b}}" 1231 a=12345 1232 aa[(e)*]=star 1233 accum=() 1234 alias '..'='cd ..' 1235 alias -g ...='../..' 1236 alias -g NF='*(.om[1])' # newest file 1237 alias gcd="cd $MCD" # double quote stops once only evaluation 1238 alias mcd="MCD=$(pwd)" # double quote stops once only evaluation 1239 anchortext=${${(C)url//[_-]/ }:t} # titlecase 1240 arr=(veldt jynx grimps waqf zho buck) 1241 array=(~/.zshenv ~/.zshrc ~/.zlogout) 1242 autoload edit-command-line 1243 autoload -Uz up-line-or-beginning-search 1244 autoload colors ; colors 1245 bindkey "^N" most-recent-file 1246 bindkey -s "^[OS" "\^d\^c\n" 1247 bindkey -s "^[[18~" "ls -l\n" 1248 c=(*.c) o=(*.o(N)) eval 'ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}' 1249 cd !$:h 1250 cd !?ls 1251 diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort) 1252 dpath=${upath/#\/c\//c:/} # convert /c/path/ to c:\path\ 1253 drive=$([[ "$LOGNAME" != davidr ]] && echo '/o' || echo '/c') # trad way 1254 drive=${${${LOGNAME:#davidr}:+/o}:-/c} # zsh way 1255 egrep -i "^ *mail\(" **/*.php 1256 eval "$1=$PWD" 1257 eval "m=($(cat -- $nameoffile)" 1258 feh $FILES[$RANDOM%$#FILES+1] 1259 foo="twinkle twinkle little star" sub="t*e" rep="spy" 1260 foo=$'bar\n\nbaz\n' 1261 foo=fred-goat-dog.jpg 1262 fred=$((6**2 + 6)) # can do maths 1263 (( $# == 0 )); 1264 [ "$p1" = "end" ] || [ "$p1" = "-e" ] 1265 [ $# -gt 0 ] # parameter cnt > 0 (arguments) 1266 [ $cnt -eq 1 ] 1267 [[ "$1" == [0-9] ]] # if $1 is a digit 1268 [[ "$p2" == *[a-zA-Z][a-zA-Z][a-zA-Z]* ]] # contains at least 3 letters 1269 [[ "$pwd" == *$site2* ]] 1270 [[ "$url" = www* ]] # begins with www 1271 [[ -e /c/aam/z$1 ]] # file exists 1272 p1 p2 p3 1273 pcre_compile -m "\d{5}" 1274 pcre_match -b -- $string 1275 perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > $(print NF).txt 1276 ps -p $$ | grep $$ | awk '{print $NF}' 1277 r oldstr=newstr 1278 r\m $(locate nohup.out) 1279 read -r line <&$fd; print -r - $line 1280 read ans ; # read in a parameter 1281 setopt EXTENDED_GLOB # lots of clever stuff requires this 1282 source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE 1283 ssh -t root@192.18.001.001 'sh -c "cd /tmp && exec zsh -l"' 1284 ssh 192.168.1.218 -l root "zsh -c 'for i (/usr/*(/)) {ls \$i }'" 1285 sshpass -p myppassword scp -rp * user@18.128.158.158:${PWD/staging/release} 1286 str=aa,bb,cc;print ${(j:,:)${(qq)${(s:,:)str}}} # quotify a string 1287 tel blenkinsop | grep -o "[[:alnum:][:graph:]]*@[[:alnum:][:graph:]]*" # filter just an email address from a text stream (not zsh) 1288 touch {t,p}{01..99}.{php,html,c} # generate 600 test files 1289 touch {y,y2}.cfm 1290 trap - INT 1291 typeset "aa[one\"two\"three\"quotes]"=QQQ 1292 typeset -A aa 1293 typeset -A ass_array; ass_array=(one 1 two 2 three 3 four 4) 1294 typeset -A convtable 1295 typeset -i 16 y 1296 unsetopt XTRACE VERBOSE 1297 unsetopt localtraps 1298 upath=${wpath//\\/\/} # convert backslashes to forward slashes (Dos to Unix 1299 url='www.some.com/some_strIng-HERe' 1300 val=a:b:c 1301 var=133;if [[ "$var" = <-> ]] ; then echo "$var is numeric" ;fi 1302 var=ddddd; [[ "$var" =~ ^d+$ ]] && echo matched || echo did not match 1303 var=dddee; regexp="^e+$"; [[ "$var" =~ $regexp ]] && echo $regexp matched $var || echo $regexp did not match $var 1304 vared -p "choose 1-3 : " -c ans 1305 vared PATH 1306 whence -vsa ${(k)commands[(I)zsh*]} # search for zsh* 1307 widget 1308 wpath=${wpath//\//\\\\} # substitute Unix / with dos \ slashes 1309 x=$? 1310 zmodload -F zsh/stat b:zstat 1311 zsh -lxic : 2> >(grep "> alias 'web'") 1312 { paste <(cut -f1 file1) <(cut -f3 file2) } > >(process)