简体   繁体   中英

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 . However when I start up a terminal (I use terminator), the error doesn't show and both .bashrc and .bash_aliases are properly sourced.

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.

There is no error in the function as far as I know, but here's the code anyways:

#!/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 ?

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 . 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. 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:

So the answer is simple... I called the function the same name as the alias, so it confused itself...

I changed html () to htmlFunc () and now it works.

Thanks tDarkCrystal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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