[英]Autofill is failing after creating a “local” alias in my ~/.bashrc file
我在.bashrc文件中添加了別名。 我這樣做並運行源〜/ .bashrc之后,自動填充開始在Ubuntu命令提示符下引發錯誤。 該錯誤將我定向到bash_completion文件的第295行,以查找錯誤的語法。
當我打開該文件並轉到第295行時,看不到任何錯誤的語法。 這是我要添加的代碼行以及我收到的錯誤。
我最初添加到.bashrc
文件中的別名:
alias local='cd /mnt/c/Users/NYCZE/OneDrive/'
當我運行source ~/.bashrc
來實現此別名時拋出錯誤:
bash: /usr/share/bash-completion/bash_completion: line 295: syntax error near unexpected token `('
bash: /usr/share/bash-completion/bash_completion: line 295: `('
在我的bash_completion
文件中包含第295行的函數:
__reassemble_comp_words_by_ref()
{
local exclude i j line ref # This line right here is the problem one
# Exclude word separator characters?
if [[ $1 ]]; then
# Yes, exclude word separator characters;
# Exclude only those characters, which were really included
exclude="${1//[^$COMP_WORDBREAKS]}"
fi
# Default to cword unchanged
printf -v "$3" %s "$COMP_CWORD"
# Are characters excluded which were former included?
if [[ $exclude ]]; then
# Yes, list of word completion separators has shrunk;
line=$COMP_LINE
# Re-assemble words to complete
for (( i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
# Is current word not word 0 (the command itself) and is word not
# empty and is word made up of just word separator characters to
# be excluded and is current word not preceded by whitespace in
# original line?
while [[ $i -gt 0 && ${COMP_WORDS[$i]} == +([$exclude]) ]]; do
# Is word separator not preceded by whitespace in original line
# and are we not going to append to word 0 (the command
# itself), then append to current word.
[[ $line != [[:blank:]]* ]] && (( j >= 2 )) && ((j--))
# Append word separator to current or new word
ref="$2[$j]"
printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}"
# Indicate new cword
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
# Remove optional whitespace + word separator from line copy
line=${line#*"${COMP_WORDS[$i]}"}
# Start new word if word separator in original line is
# followed by whitespace.
[[ $line == [[:blank:]]* ]] && ((j++))
# Indicate next word if available, else end *both* while and
# for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
done
# Append word to current word
ref="$2[$j]"
printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}"
# Indicate new cword
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
# Remove optional whitespace + word separator from line copy
line=${line#*"${COMP_WORDS[$i]}"}
# Start new word if word separator in original line is
# followed by whitespace.
[[ $line == [[:blank:]]* ]] && ((j++))
# Indicate next word if available, else end *both* while and
# for loop
(( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2
done
# Append word to current word
ref="$2[$j]"
printf -v "$ref" %s "${!ref}${COMP_WORDS[i]}"
# Remove optional whitespace + word from line copy
line=${line#*"${COMP_WORDS[i]}"}
# Indicate new cword
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
done
[[ $i == $COMP_CWORD ]] && printf -v "$3" %s "$j"
else
# No, list of word completions separators hasn't changed;
for i in ${!COMP_WORDS[@]}; do
printf -v "$2[i]" %s "${COMP_WORDS[i]}"
done
fi
}
local
是一個保留關鍵字,在許多Bash完成包中廣泛使用,並且通常在具有功能的Bash代碼中使用。 您真的不想覆蓋它,因為那樣會破壞那些程序包。 別稱您的別名。
(也許也根本不使用別名-Shell函數的用途更加廣泛-但這不會改變問題的實質。)
local
是內置的shell。 你可以從這里看到
type local
別名之后,它已變成cd
。 現在,相同type
命令將給出
local is aliased to `cd /mnt/c/Users/NYCZE/OneDrive/'
現在,我的/ usr / share / bash-completion / bash_completion文件中的第295行是
local cword words=()
因此, local
不再具有該文件所期望的行為。 文件中的行類似地使用local
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.