⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq

📁 android-w.song.android.widget
💻
📖 第 1 页 / 共 5 页
字号:
	new $'...' and $"..." quoting	FIGNORE (but bash uses GLOBIGNORE), HISTCMD	brace expansion and set -B	changes to kill builtin	`command', `builtin', `disown' builtins	echo -e	exec -c/-a	printf %T modifier	read -A (bash uses read -a)        read -t/-d	trap -p	`.' restores the positional parameters when it completes	set -o notify/-C	set -o pipefail	set -G (-o globstar) and **	POSIX.2 `test'	umask -S	unalias -a	command and arithmetic substitution performed on PS1, PS4, and ENV	command name completion, TAB displaying possible completions	ENV processed only for interactive shells	The `+=' assignment operator	the `;&' case statement "fallthrough" pattern list terminator	csh-style history expansion and set -H	negative offsets in ${param:offset:length}	redirection operators preceded with {varname} to store fd number in varname	DEBUG can force skipping following command	[[ -v var ]] operator (checks whether or not var is set)Section D:  Why does bash do some things differently than other Unix shells?D1) Why does bash run a different version of `command' than    `which command' says it will?On many systems, `which' is actually a csh script that assumesyou're running csh.  In tcsh, `which' and its cousin `where'are builtins.  On other Unix systems, `which' is a perl scriptthat uses the PATH environment variable.  Many Linux distributionsuse GNU `which', which is a C program that can understand shellaliases.The csh script version reads the csh startup files from yourhome directory and uses those to determine which `command' willbe invoked.  Since bash doesn't use any of those startup files,there's a good chance that your bash environment differs fromyour csh environment.  The bash `type' builtin does everything`which' does, and will report correct results for the runningshell.  If you're really wedded to the name `which', try addingthe following function definition to your .bashrc:	which()	{		builtin type "$@"	}If you're moving from tcsh and would like to bring `where' alongas well, use this function:	where()	{		builtin type -a "$@"	}D2) Why doesn't bash treat brace expansions exactly like csh?The only difference between bash and csh brace expansion is thatbash requires a brace expression to contain at least one unquotedcomma if it is to be expanded.  Any brace-surrounded word notcontaining an unquoted comma is left unchanged by the braceexpansion code.  This affords the greatest degree of shcompatibility. Bash, ksh, zsh, and pd-ksh all implement brace expansion this way. D3) Why doesn't bash have csh variable modifiers?Posix has specified a more powerful, albeit somewhat more cryptic,mechanism cribbed from ksh, and bash implements it.${parameter%word}        Remove smallest suffix pattern.  The WORD is expanded to produce        a pattern.  It then expands to the value of PARAMETER, with the        smallest portion of the suffix matched by the pattern deleted.        x=file.c        echo ${x%.c}.o        -->file.o${parameter%%word}        Remove largest suffix pattern.  The WORD is expanded to produce        a pattern.  It then expands to the value of PARAMETER, with the        largest portion of the suffix matched by the pattern deleted.        x=posix/src/std        echo ${x%%/*}        -->posix${parameter#word}        Remove smallest prefix pattern.  The WORD is expanded to produce        a pattern.  It then expands to the value of PARAMETER, with the        smallest portion of the prefix matched by the pattern deleted.        x=$HOME/src/cmd        echo ${x#$HOME}        -->/src/cmd${parameter##word}        Remove largest prefix pattern.  The WORD is expanded to produce        a pattern.  It then expands to the value of PARAMETER, with the        largest portion of the prefix matched by the pattern deleted.        x=/one/two/three        echo ${x##*/}        -->threeGiven	a=/a/b/c/d	b=b.xxx	csh			bash		result	---			----		------	$a:h			${a%/*}		   /a/b/c	$a:t			${a##*/}	   d	$b:r			${b%.*}		   b	$b:e			${b##*.}	   xxxD4) How can I make my csh aliases work when I convert to bash?Bash uses a different syntax to support aliases than csh does. The details can be found in the documentation.  We have provideda shell script which does most of the work of conversion for you;this script can be found in ./examples/misc/aliasconv.sh.  Here ishow you use it:  Start csh in the normal way for you.  (e.g., `csh')  Pipe the output of `alias' through `aliasconv.sh', saving theresults into `bash_aliases':  	alias | bash aliasconv.sh >bash_aliases  Edit `bash_aliases', carefully reading through any createdfunctions.  You will need to change the names of some csh specificvariables to the bash equivalents.  The script converts $cwd to$PWD, $term to $TERM, $home to $HOME, $user to $USER, and $promptto $PS1.  You may also have to add quotes to avoid unwantedexpansion.For example, the csh alias:  	alias cd 'cd \!*; echo $cwd'  is converted to the bash function:	cd () { command cd "$@"; echo $PWD ; }The only thing that needs to be done is to quote $PWD:  	cd () { command cd "$@"; echo "$PWD" ; }  Merge the edited file into your ~/.bashrc.There is an additional, more ambitious, script inexamples/misc/cshtobash that attempts to convert your entire cshenvironment to its bash equivalent.  This script can be run assimply `cshtobash' to convert your normal interactiveenvironment, or as `cshtobash ~/.login' to convert your loginenvironment. D5) How can I pipe standard output and standard error from one command to    another, like csh does with `|&'?Use	command 2>&1 | command2The key is to remember that piping is performed before redirection, sofile descriptor 1 points to the pipe when it is duplicated onto filedescriptor 2.D6) Now that I've converted from ksh to bash, are there equivalents to    ksh features like autoloaded functions and the `whence' command?There are features in ksh-88 and ksh-93 that do not have direct bashequivalents.  Most, however, can be emulated with very little trouble.ksh-88 feature		Bash equivalent--------------		---------------compiled-in aliases	set up aliases in .bashrc; some ksh aliases are			bash builtins (hash, history, type)coprocesses		named pipe pairs (one for read, one for write)typeset +f		declare -Fcd, print, whence	function substitutes in examples/functions/kshenvautoloaded functions	examples/functions/autoload is the same as typeset -furead var?prompt		read -p prompt varksh-93 feature		Bash equivalent--------------		---------------sleep, getconf		Bash has loadable versions in examples/loadables${.sh.version}		$BASH_VERSIONprint -f		printfhist			alias hist=fc$HISTEDIT		$FCEDITSection E:  How can I get bash to do certain things, and why does bash do	    things the way it does?E1) Why is the bash builtin `test' slightly different from /bin/test?The specific example used here is [ ! x -o x ], which is false.Bash's builtin `test' implements the Posix.2 spec, which can besummarized as follows (the wording is due to David Korn):   Here is the set of rules for processing test arguments.      0 Args: False    1 Arg:  True iff argument is not null.    2 Args: If first arg is !, True iff second argument is null.	    If first argument is unary, then true if unary test is true	    Otherwise error.    3 Args: If second argument is a binary operator, do binary test of $1 $3	    If first argument is !, negate two argument test of $2 $3	    If first argument is `(' and third argument is `)', do the	    one-argument test of the second argument.	    Otherwise error.    4 Args: If first argument is !, negate three argument test of $2 $3 $4.	    Otherwise unspecified    5 or more Args: unspecified.  (Historical shells would use their    current algorithm).   The operators -a and -o are considered binary operators for the purposeof the 3 Arg case.   As you can see, the test becomes (not (x or x)), which is false.E2) Why does bash sometimes say `Broken pipe'?If a sequence of commands appears in a pipeline, and one of thereading commands finishes before the writer has finished, thewriter receives a SIGPIPE signal.  Many other shells special-caseSIGPIPE as an exit status in the pipeline and do not report it. For example, in:        ps -aux | head  `head' can finish before `ps' writes all of its output, and pswill try to write on a pipe without a reader.  In that case, bashwill print `Broken pipe' to stderr when ps is killed by aSIGPIPE. As of bash-3.1, bash does not report SIGPIPE errors by default.  Youcan build a version of bash that will report such errors.E3) When I have terminal escape sequences in my prompt, why does bash    wrap lines at the wrong column?Readline, the line editing library that bash uses, does not knowthat the terminal escape sequences do not take up space on thescreen.  The redisplay code assumes, unless told otherwise, thateach character in the prompt is a `printable' character thattakes up one character position on the screen. You can use the bash prompt expansion facility (see the PROMPTINGsection in the manual page) to tell readline that sequences ofcharacters in the prompt strings take up no screen space. Use the \[ escape to begin a sequence of non-printing characters,and the \] escape to signal the end of such a sequence. E4) If I pipe the output of a command into `read variable', why doesn't    the output show up in $variable when the read command finishes?This has to do with the parent-child relationship between Unixprocesses.  It affects all commands run in pipelines, not justsimple calls to `read'.  For example, piping a command's outputinto a `while' loop that repeatedly calls `read' will result inthe same behavior.Each element of a pipeline, even a builtin or shell function,runs in a separate process, a child of the shell running thepipeline.  A subprocess cannot affect its parent's environment. When the `read' command sets the variable to the input, thatvariable is set only in the subshell, not the parent shell.  Whenthe subshell exits, the value of the variable is lost. Many pipelines that end with `read variable' can be convertedinto command substitutions, which will capture the output ofa specified command.  The output can then be assigned to avariable:	grep ^gnu /usr/lib/news/active | wc -l | read ngroupcan be converted into	ngroup=$(grep ^gnu /usr/lib/news/active | wc -l)This does not, unfortunately, work to split the text amongmultiple variables, as read does when given multiple variablearguments.  If you need to do this, you can either use thecommand substitution above to read the output into a variableand chop up the variable using the bash pattern removalexpansion operators or use some variant of the followingapproach.Say /us

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -