
Bash 쉘에서 별칭을 만들 수 없는 이유는 무엇입니까?
$ alias fooo="echo bac"
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
$ alias fooo='echo bac'
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
$ fooo
fooo: command not found
$ alias fooo
bash: alias: fooo: not found
다른 bash 쉘에서 위 명령은 별칭 생성에 성공합니다.
$ alias fooo="echo bac"
$ fooo
bac
첫 번째 셸에서 새 셸을 시작하거나(입력하고 bash
Enter 누르기) 새 로그인 셸을 시작하면(입력 bash -l
) 위 명령도 두 번째 셸에서처럼 성공합니다.
alias
첫 번째 쉘의 명령 에 대한 응답에 관하여
$ which alias
$ whereis alias
alias:
$ builtin alias fooo="echo bac"
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
$ type alias
alias is a shell builtin
$ type -a alias
alias is a shell builtin
$ unalias alias
bash: unalias: alias: not found
echo
첫 번째 쉘의 주석에 대해
$ echo hello
hello
$ whereis echo
echo: /bin/echo /usr/share/man/man1/echo.1.gz
$ which echo
/bin/echo
답변1
첫 번째 셸에서 별칭을 정의하려고 하면 기존 별칭이 포함된 출력을 얻습니다. 이것은 잘못된 것입니다. 두 번째 셸에서와 같이 출력이 없어야 합니다. 'alias'라는 별칭 이름을 정의하면 동일한 문제가 재현되었습니다.
실제로 실행되는 것이 무엇인지 알아보세요. 그냥 실행 builtin alias
하거나 builtin alias foo="echo bar"
별칭 명령을 강제로 사용하도록 해보세요.
답변2
첫 번째 셸에서 다음과 같은 방식으로 정의된 함수가 있습니다.
alias(){ builtin alias ; }
type alias
그 가설을 확인해야합니다.