简体   繁体   English

sourcing.bashrc 出错,但第一次加载时没有

[英]Error on sourcing .bashrc, but not when loading it for first time

I'm getting an error from my .bash_aliases file when I run source.bashrc .运行source.bashrc时,我的.bash_aliases文件出现错误。 However when I start up a terminal (I use terminator), the error doesn't show and both .bashrc and .bash_aliases are properly sourced.但是,当我启动终端(我使用终结器)时,不会显示错误,并且.bashrc.bash_aliases的来源都是正确的。

The error I'm getting is:我得到的错误是:

bash: /home/ciaran/.bash_aliases: line 33: syntax error near unexpected token `('
bash: /home/ciaran/.bash_aliases: line 33: `html ()'

This refers to a custom alias I put in place for pandoc to convert.md to.html.这是指我为pandoc设置的自定义别名,以将.md 转换为.html。

There is no error in the function as far as I know, but here's the code anyways:据我所知,function 没有错误,但无论如何,这里是代码:

#!/bin/sh

#[...] Regular aliases for ls and stuff
#[...] Other Stuff that is irrelevant

html ()
{
pandoc -f markdown -t html $1 > /home/ciaran/Desktop/r.html
wait
firefox /home/ciaran/Desktop/r.html;
wait
sleep 5
rm /home/ciaran/Desktop/r.html;
}

alias html='html 2>/dev/null'

#=====================================================================================

alias src="clear && source ~/.bashrc"

What could cause an error to pop up only when I run src ?仅当我运行src时,什么可能导致错误弹出?

Am I missing something blatantly obvious?我错过了一些明显的东西吗?

EDIT: I just remembered a detail that might influence Stuff: I activate an anaconda environment as the last line of .bashrc .编辑:我只记得一个可能影响 Stuff 的细节:我激活了 anaconda 环境作为.bashrc的最后一行。 I don't know if this can cause issues or not, but I thought I'd mention it.我不知道这是否会导致问题,但我想我会提到它。

You need a space in your function declaration.您的 function 声明中需要一个空格。 That's why the syntax error is reporting on that line.这就是在该行上报告语法错误的原因。

html () {
pandoc -f markdown -t html $1 > /home/ciaran/Desktop/r.html
wait
firefox /home/ciaran/Desktop/r.html;
wait
sleep 5
rm /home/ciaran/Desktop/r.html;
}

See this for clean up.看到这个清理。


print_pretty () 
{ 
    stat -c$'%F\n%n' * | awk -vC0='\033[1;34m' -vC1='\033[00m' -vC2='\033[1;32m' -vC3='\033[1;36m' '/^directory/ {getline LEFT[++DC]; next} {getline RIGHT[++FC]} {for (i=1; i<=FC; i++) {if (system("[ -h " RIGHT[i] " ]") == 0) RIGHT[i]=C3 RIGHT[i]; if (system("[ -x " RIGHT[i] " ]") == 0) RIGHT[i]=C2 RIGHT[i]}} END {for (i=1; i<=(DC>FC?DC:FC); i++) printf "%-50s%s\n", C0 LEFT[i], C1 RIGHT[i]}'
}

# execute function first
print_pretty

# now make alias
alias l='print_pretty 2>/dev/null' #<-- sneaky ignore errors command here!

#=====================================================================================

html ()
{
pandoc -f markdown -t html $1 > /home/ciaran/Desktop/r.html
wait
firefox /home/ciaran/Desktop/r.html;
wait
sleep 5
rm /home/ciaran/Desktop/r.html;
}

# call function
html

#=====================================================================================

alias src='clear && source ~/.bashrc'


Here's to resume what the answer by tDarkCrystal brought to fruition:这是恢复 tDarkCrystal 的答案所带来的结果:

So the answer is simple... I called the function the same name as the alias, so it confused itself...所以答案很简单……我把function和别名同名,所以自己搞糊涂了……

I changed html () to htmlFunc () and now it works.我将html ()更改为htmlFunc ()现在它可以工作了。

Thanks tDarkCrystal谢谢 tDarkCrystal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM