# распаковка архива
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "я не в курсе как распаковать '$1'..." ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# упаковка в архив
pack () {
if [ $1 ] ; then
case $1 in
tbz) tar cjvf $2.tar.bz2 $2 ;;
tgz) tar czvf $2.tar.gz $2 ;;
tar) tar cpvf $2.tar $2 ;;
bz2) bzip $2 ;;
gz) gzip -c -9 -n $2 > $2.gz ;;
zip) zip -r $2.zip $2 ;;
7z) 7z a $2.7z $2 ;;
*) echo "'$1' cannot be packed via pk()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# перенаправляем
READNULLCMD=${PAGER}
# цветной grep
alias grep='grep --color=auto'
alias df='df -h'
alias du='du -h'
alias ls='ls -F --color=auto'
alias ll="ls -lah"
alias man="LC_ALL="ru_RU.UTF-8" man"
# разукрашиваем некоторые команды с помощью grc
[[ -f /usr/bin/grc ]] && {
alias ping="grc --colour=auto ping"
alias traceroute="grc --colour=auto traceroute"
alias make="grc --colour=auto make"
alias diff="grc --colour=auto diff"
alias cvs="grc --colour=auto cvs"
alias netstat="grc --colour=auto netstat"
}
# разукрашиваем логи с помощью grc
alias logc="grc cat"
alias logt="grc tail"
alias logh="grc head"
alias -g HE='2>>( sed -ue "s/.*/$fg_bold[red]&$reset_color/" 1>&2 )' # Highlight Errors
# Установка PROMT
#
# левый
# PROMPT="%{$fg_bold[yellow]%}G$%{$reset_color%}"
# правый - когда всё гуд хороший смайлик, когда ошибка то грусный, ну и цветные ясен фиг
# RPROMPT="%{$fg_bold[grey]%}%~/ %{$reset_color%}% %(?,%{$fg[green]%}:%)%{$reset_color%},%{$fg[red]%}:(%{$reset_color%}"
# вопрос на автокоррекцию
# SPROMPT='zsh: Заменить '\''%R'\'' на '\''%r'\'' ? [Yes/No/Abort/Edit] '
#
#
[[ ${TERM} =~ screen ]] && precmd() { print -Pn "\e]2;%2d\a" } || RPROMPT='%F{white}%~%f'
PS1='%B%F{cyan}%#%f%b '
PS2=' '
PS3='%B%F{white}?# %b%f%F{red}%# %f'
PS4='%B%F{white}%_ %b%f%F{magenta}%# %f%B%F{white}+%N:%i %b%f%F{magenta}%# %f'
Доброго времени!
Как не удивительно, данное поведение описано в документации.
Данное свойство (поведение) именуют clobber. Википедия даёт ему именование globbering, http://en.wikipedia.org/wiki/Clobbering
Clobber позволяет определить поведение программы при записи в существующий (или не существующий) файл (сегмент памяти, …).
CLOBBER (переменная, которой именуется это свойство в zsh) или noclobber (наиболее частое именование в прочих shell, а также оригинальное название переменной) появилось в C-shell (первая версия csh появилась в 1978 году).
Исходя из названий понятно, что noclobber равняется неустановленному CLOBBER, и наоборот.
В руководстве к csh во втором выпуске BSD (1979 год) она описывается следующим образом, http://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/man/csh.u:
Input/output
The standard input and standard output of a command may be redi‐
rected with the following syntax: < name
Open file (which is first variable, command and filename expand‐
ed) as the standard input. << word
Read the shell input up to a line which is identical to is not
subjected to variable, filename or command substitution, and each
input line is compared to before any substitutions are done on
this input line. Unless a quoting ‘\’, ‘"’, ‘’ or ‘’ appears in
variable and command substitution is performed on the intervening
lines, allowing ‘\’ to quote ‘$’, ‘\’ and ‘’. Commands which are
substituted have all blanks, tabs, and newlines preserved, except
for the final newline which is dropped. The resultant text is
placed in an anonymous temporary file which is given to the com‐
mand as standard input. > name
>! name
>& name
>&! name
The file is used as standard output. If the file does not exist
then it is created; if the file exists, its is truncated, its
previous contents being lost. If the variable noclobber
is set, then the
file must not exist or be a character special file (e.g. a termi‐
nal or ‘/dev/null’) or an error results. This helps prevent ac‐
cidental destruction of files. In this case the ‘!’ forms can be
used and suppress this check. The forms involving ‘&’ route the
diagnostic output into the specified file as well as the standard
output. is expanded in the same way as ‘<’ input filenames are.
>> name
>>& name
>>! name
>>&! name
Uses file as standard output like ‘>’ but places output at the
end of the file. If the variable is set, then it is an error for
the file not to exist unless one of the ‘!’ forms is given. Oth‐
erwise similar to ‘>’. If a command is run detached (followed by
‘&’) then the default standard input for the command is the empty
file ‘/dev/null’. Otherwise the command receives the environment
in which the shell was invoked as modified by the input‐output
parameters and the presence of the command in a pipeline. Thus,
unlike some previous shells, commands run from a file of shell
commands have no access to the text of the commands by default;
rather they receive the original standard input of the shell.
The ‘<<’ mechanism should be used to present inline data. This
permits shell command scripts to function as components of pipe‐
lines and allows the shell to block read its input. Diagnostic
output may be directed through a pipe with the standard output.
Simply use the form ‘|&’ rather than just ‘|’.
noclobber описано в стандарте POSIX, и следовательно поддерживается в POSIX-совместимых shell.
Отличие clobber POSIX'а от zsh/tcsh в том, что в последних при «до записи» в несуществующий файл (при установленном noclobber в tcsh, и при неустановленном GLOBBER в zsh) будет выведено сообщение об ошибке.
text
:~% echo $shell
/usr/bin/tcsh
:~% unset noclobber
:~% ls file
ls: cannot access file: No such file or directory
:~% set noclobber
:~% echo "something" >> file
file: No such file or directory.
:~% echo "something" > file
:~% echo "another something" > file
: File exists.
:~% echo "another something" >> file
:~% cat file
something
another something
% echo $0
zsh
% ls file
ls: cannot access file: No such file or directory
% set +o CLOBBER
% echo "something" > file
% echo "something" > file
zsh: file exists: file
% echo "another something" >> file
% cat file
something
another something
% rm file
% echo "something" >> file
zsh: no such file or directory: file
Из руководства zsh:
Redirection
If a command is followed by & and job control is not active, then the default standard input for the command is the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications.
The following may appear anywhere in a simple command or may precede or follow a complex command. Expansion occurs before word or digit is used except as noted below. If the result of substitution on word produces more than one filename, redirection occurs for each separate filename in turn.
< word
Open file word for reading as standard input.
<> word
Open file word for reading and writing as standard input. If the file does not exist then it is created.
> word
Open file word for writing as standard output. If the file does not exist then it is created. If the file exists, and the CLOBBER option is unset, this causes an error; otherwise, it is truncated to zero length.
>| word
>! word
Same as >, except that the file is truncated to zero length if it exists, even if CLOBBER is unset.
>> word
Open file word for writing in append mode as standard output. If the file does not exist, and the CLOBBER option is unset, this causes an error; otherwise, the file is created.
Options
Input/Output
CLOBBER (+C, ksh: +C) <D>
Allows ‘>’ redirection to truncate existing files, and ‘>>’ to create files. Otherwise ‘>!’ or ‘>|’ must be used to truncate a file, and ‘>>!’ or ‘>>|’ to create a file.