#-------------------------------------------------------------------------- # bashref-tests.sh # bash tests for Scintilla's LexBash.cxx # from bashref 2.5b documentation for bash 2.05b July 2002 (RH9) # Kein-Hong Man Public Domain 2006-01-14 #-------------------------------------------------------------------------- # 20040408 completed for initial LexBash.cxx version # 20050609 comment folding tests # 20051107 HERE doc tests #-------------------------------------------------------------------------- #-------------------------------------------------------------------------- # from coreutils-4.5.3 (RH9) basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir dircolors dirname du echo env expand expr factor false fmt fold groups head hostid id install join link ln logname ls md5sum mkdir mkfifo mknod mv nice nl nohup od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir seq sha1sum shred sleep sort split stat stty su sum sync tac tail tee test touch tr true tsort tty uname unexpand uniq unlink users vdir wc who whoami yes #-------------------------------------------------------------------------- # metacharacters | & ; ( ) < > blank # control operators || & && ; ;; ( ) | # reserved words (1st word of a command or 3rd word of a case or for command) ! case do done elif else esac fi for function if in select then until while { } time [[ ]] #-------------------------------------------------------------------------- # comment until end of line # backslash for general line continuation (CRLF)\ this should be highlighted as a comment # backslash for general line continuation (LF)\ this should be highlighted as a comment #-------------------------------------------------------------------------- # comment folding tests # a single comment is not folded # indented single comment is not folded # indented single comment is not folded print; # a comment of 2 or more lines is folded # FOO # a comment of 2 or more lines is folded # FOO # BAR print; # a comment of 2 or more lines is folded # FOO # BAR print; # a comment of 2 or more lines is folded # FOO # BAR print; #-------------------------------------------------------------------------- \c \# \" \' # escapes character 'c' # single quoted character, '\'' is illegal '\c' # illegal in Bash, I think 'literal string' 'multiline literal' # multiline literal 'multiline literal \ with newlines continuation' "string" # double quoted strings "multiline string" # multiline string "multiline string \ with newlines continuation" # backslash only for \$ \` \" \\ \newline ONLY (not implemented) # $,`,*,@ have special meaning "\$\`\"\\" # escaped characters "\a\b\c" # works as well!! $'string' # ANSI-C quoting # allows the following escapes: # \a \b \e \f \n \r \t \v \\ \' # \nnn{1,3} \xHH{1,2} hex,octal # \cx (x is control char) $'\a\b\e\f\n\r\t\b\\\'\012\xAB\cA' $"string" # locale-translated string $"locale-translated multiline string" # multiline locale-translated string $"locale-translated multiline string \ with newlines continuation" #-------------------------------------------------------------------------- # commands command [options] | command [options] | ... command-command # external command formats command+command command.ext # newlines delimit commands ; # command delimiter, may be replaced by one or more newlines command & # async command1 && command2 command1 || command2 #-------------------------------------------------------------------------- # looping constructs until commands; do commands; done while commands; do commands; done for name [in words...]; do commands; done for (( expr1; expr2; expr3 )) ; do commands; done break continue #-------------------------------------------------------------------------- # conditional constructs if commands; then commands; elif commands; then commands; else commands; fi case word in [ [(] pattern [| pattern]...) command-list;;]... esac select name [in words...]; do commands; done #-------------------------------------------------------------------------- (( expression )) let "expression" [[ expression ]] (expression) !expression expr1 && expr2 expr1 || expr2 #-------------------------------------------------------------------------- # grouping commands ( list ) # parentheses are operators { list; } # braces are reserved words # list must be terminated by ; or \n [function] name () { command-list; } # same requirements for {} name=[value] #-------------------------------------------------------------------------- # positional parameters $N # where N is 1-9 ${N} # where N can be more than a single digit # special parameters $* $@ $# $? $- $$ $! $0 $_ $*+$@-$#*$? # mixed $NAME $FOO$BAR # brace expansion (where '{' is not '${', at least one comma) a{d,c,b}e -> ade ace abe #-------------------------------------------------------------------------- # tilde expansion ~/foo #/ ~foo/bar #/ ~+/foo #/ ~-/foo #/ ~N ~+N ~-N #-------------------------------------------------------------------------- # shell parameter expansion (# } may be escaped by a backslash) ${foo}+ ${foo\}bar}+ ${parameter:-word}- ${parameter:=word}* ${parameter:?word}/ ${parameter:+word}? !${parameter:offset} ${parameter:offset:length}% =${!prefix*} ${#parameter}= ${parameter#word}> ${parameter##word} ${parameter%word} ${parameter%word} ${parameter/pattern/string} ${parameter//pattern/string} #-------------------------------------------------------------------------- # command substitution $(command) `command` $`command` # seen in configure script # for backquotes only, $, ` and \ can be escaped by \, # otherwise \ is a literal (not implemented) `\$\`\\` $(\$\`\\) # technically illegal? # arithmetic expression $(( expression )) # process substitution <(list) >(list) #-------------------------------------------------------------------------- # filename expansion # files with '.' prefixes must have the dot matched explicitly # special pattern characters * ? [...] [!...] [^...] # can use - as range operator [:class:] # character classes [:alnum:] [:alpha:] [:ascii:] [:blank:] [:cntrl:] [:digit:] [:graph:] [:lower:] [:print:] [:punct:] [:space:] [:upper:] [:word:] [:xdigit:] [=c=] # equivalence class of character c [.symbol.] # match collating symbol 'symbol' # extended pattern matching operators # patterns in a list are separated by | ?(pattern-list) *(pattern-list) +(pattern-list) @(pattern-list) !(pattern-list) #-------------------------------------------------------------------------- # redirection [n][|]word 2>word 2>|word [n]>>word 2>>word &>word >&word >word 2>&1 #-------------------------------------------------------------------------- # HERE documents # no trailing blanks, characters in word may be quoted ('c') # non-HERE documents <<$foo <<1 <<0x12 <<=8 << 8 << $bar # HERE documents (basic) # no trailing blanks, characters in word may be quoted ('c') <>Policy.sh # [snipped] !GROK!THIS! # this is a comment #-------------------------------------------------------------------------- # duplicating and moving file descriptors [n]<&word [n]>&word [n]<&digit- [n]>&digit- # opening for R/W [n]<>word #-------------------------------------------------------------------------- # Bash number formats # errors are highlighted when dealing with digits only 0123 0567 # octal good 08 0789 077ABC # octal errors 0xDEAD 0X1234 # hex good 0xABCMNO 0XGHI # hex errors # extended "[base#]n" format where base is between 2-64 # digits range are 0-9a-zA-Z@_ # if base <= 36, then alphabets are case insensitive 2#10101 # binary 2#23456 # error 8#0123456789AB # error 16#abcDEF123 16#abcpqr # error 64#xyzXYZ@_789 # full base-64 567+0123*0xBCD # with operators (4#0123-3#012) #-------------------------------------------------------------------------- # bash conditional expressions # all single letter ones are marked as keywords # or, better to disable it? -a -b -c -d -e -f -g -h -k -p -r -s -t -u -w -x -O -G -L -S -N -nt --ot -ef -o -z -n == != < > -eq -ne -lt -le -gt -ge #-------------------------------------------------------------------------- # shell arithmetic id++ id-- # ambiguous, +|- may also be used in filenames ++id --id + - ! ~ ** * / % + - << $baz >> <= >= < > == != & ^ | && || expr ? expr : expr = *= /= %= += -= <<= >>= &= ^= |= , #-------------------------------------------------------------------------- # arrays name[subscript]=value declare -a name[subscript] name=(value1 ... valuen) ${name[subscript]} ${name[@]} ${name[*]} ${#name[subscript]} unset name[subscript] #-------------------------------------------------------------------------- # some built-in commands # -options, --options aren't lexed beautifully : [arguments] . filename [arguments] break [n] cd [-L|-P] [directory] continue [n] eval [arguments] exec -cl [-a name] [command [arguments]] exit [n] export [-fn] [-p] [name[=value]] getopts optstring name [args] hash [-'r] [-p filename] [-dtl] [name] #'# fails to lex ??? to check pwd [-LP] readonly [-apf] [name]... return [n] shift [n] test # evaluate expression [...] # evaluate expression alternative times trap [-lp] [arg] [sigspec...] umask [-p] [-S] [mode] unset [-fv] [name] # expressions !expr (expr) expr1 -a expr2 expr1 -o expr2 #-------------------------------------------------------------------------- # bash built-ins alias [-p] [name[=value]...] bind [-m keymap] [-lpsvPSV] bind [-m keymap] [-q function] [-u function] [-r keyseq] bind [-m keymap] -f filename bind [-m keymap] -x keyseq:shell-command bind [-m keymap] keyseq:function-name bind readline-command builtin [shell-builtin [args]] command [-pVv] command [arguments...] declare [-afFirtx] [-p] [name[=value]] echo [-neE] [arg ...] # some escape sequences recognised enable [-n] [-p] [-f filename] [-ads] [name...] help [-s] [pattern] let expression [expression] local [option] name[=value] logout [n] printf format [arguments] read [-ers] [-a aname] [-d delim] [-n nchars] [-p prompt] [-t time-out] [-u fd] [name ...] shopt [pqsu] [-o] [optname...] source filename type [-afptP] [name ...] typeset [-afFrxi] [-p] [name[=value]] ulimit [-acdflmnpstuvSH] [limit] unalias [-a] [name ...] set [-abefhkmnptuvxBCHP] [-o option] [argument ...] #-------------------------------------------------------------------------- # shopt options cdable_vars cdspell checkhash checkwinsize cmdhist dotglob execfail expand_aliases extglob histappend histreedit histverify hostcomplete huponexit interactive_comments lithist login_shell mailwarn no_empty_cmd_completion nocaseglob nullglob progcomp promptvars restricted_shell shift_verbose sourcepath xpg_echo # set options allexport braceexpand emacs errexit hashall histexpand history ignoreeof keyword monitor noclobber noexec noglob nolog notify nounset onecmd physical posix privileged verbose vi xtrace #-------------------------------------------------------------------------- # shell variables CDPATH HOME IFS MAIL MAILPATH OPTARG OPTIND PATH PS1 PS2 # bash variables BASH BASH_ENV BASH_VERSION BASH_VERSINFO COLUMNS COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMPREPLY DIRSTACK EUID FCEDIT FIGNORE FUNCNAME GLOBIGNORE GROUPS histchars HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HOSTFILE HOSTNAME HOSTTYPE IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_NUMERIC LINENO LINES MACHTYPE MAILCHECK OLDPWD OPTERR OSTYPE PIPESTATUS POSIXLY_CORRECT PPID PROMPT_COMMAND PS3 PS4 PWD RANDOM REPLY SECONDS SHELLOPTS SHLVL TIMEFORMAT TMOUT UID #-------------------------------------------------------------------------- # directory stack dirs [+N | -N] [-clpv] popd [+N | -N] [-n] pushd [dir | +N | -N] [-n] #-------------------------------------------------------------------------- # job control bg [jobspec] fg [jobspec] jobs [-lnprs] [jobspec] jobs -x command [arguments] kill [-s sigspec] [-n signum] [-sigspec] jobspec or pid wait [jobspec or pid] disown [-ar] [-h] [jobspec...] suspend [-f] auto_resume # variable #-------------------------------------------------------------------------- # command history variables bell-style comment-begin completion-ignore-case completion-query-items convert-meta disable-completion editing-mode enable-keypad expand-tilde horizontal-scroll-mode input-meta isearch-terminators keymap mark-directories mark-modified-lines mark-symlinked-directories match-hidden-files output-meta page-completions print-completions-horizontally show-all-if-ambiguous visible-stats #-------------------------------------------------------------------------- # command key bindings keyname: function-name or macro "keyseq": function-name or macro #-------------------------------------------------------------------------- # readline conditional init constructs $if mode=xxx term=xxx application $endif $else $include filespec #-------------------------------------------------------------------------- # bindable readline commands # (these are words connected with dashes, e.g. end-of-line) #-------------------------------------------------------------------------- # programmable completion builtins compgen [option] [word] complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G glob-pat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] name [name ...] complete -pr [name ...] #-------------------------------------------------------------------------- # history interaction fc [-e ename] [-nlr] [first] [last] fc -s [pat=rep] [command] history [n] history -c history -d offset history [-anrw] [filename] history -ps arg #-------------------------------------------------------------------------- # these are not really used; more for interactive sessions # history event designators ! !n !-n !! !string !?string[?] ^string1^string2^ !# # last one fails # history word designators !! !!:$ !fi:2 0 n ^ $ % x-y/// # /// not supposed to be there blocks y * x* x- # history word modifiers h t r e p q x s/old/new/ & g # q problem