@Wahson
2016-09-04T14:06:56.000000Z
字数 1032
阅读 1003
shell
command | tips |
---|---|
${parameter:-defaultValue} | If parameter not set, use defaultValue |
u=${1:-root} | If variable $1 is not set or passed,use root as default value for u |
${USER:=foo} | Assign a value foo to the $USER variable if doesn’t already have one |
${VAR:?Error varName is not defined or is empty} | Display an Error Message If $VAR Not Passed |
_cmd="${2:? message $(cp f1 f2)}" | If $2 is not set display an error message for $2 parameter and run cp command on fly |
${#variableName} | find string length of $variableName |
${VAR#Pattern} | Remove pattern(Front of $VAR) |
${_url#*/} | Try to remove shortest matching part of $_url |
${_url##*/} | Try to remove longest matching part of $_url |
${VAR%pattern} | Remove Pattern (Back of $VAR) |
${FILE%.*} | Try to remove shortest matching part of $FILE |
${FILE%%.*} | Try to remove longest matching part of $FILE |
${varName/Pattern/Replacement} | Find and replace (only replace first occurrence) |
${varName//Pattern/Replacement} | Find and replace all occurrences |
${parameter:offset} | Like parameter.substring(offset) in Java |
${parameter:offset:length} | Like parameter.substring(offset,offset+length) in Java |
Display an Error Message and Run Command,?