LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 01-17-2012, 05:56 PM   #1
syphen
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
.bashrc help: syntax error: unexpected end of file


So I'm still fairly new to linux and I'm trying to setup a couple of functions in my .bashrc file. The functions work just fine, but I get this error:
Code:
-bash: /root/.bashrc: line 23: syntax error: unexpected end of file
I know that you probably want the code that I'm using, so here you go:
Code:
# ~/.bashrc: executed by bash(1) for non-login shells.

# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

function put(){ aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads $1 }
function put-tv(){ aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads/TV $1 }
function put-movie(){ aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads/Movies $1 }
Thanks for any help!
 
Old 01-17-2012, 06:25 PM   #2
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
Put the body of the functions on separate lines from the opening and closing braces:

Code:
put() {
  aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads "$1"
}
put-tv() {
  aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads/TV "$1"
}
put-movie() {
  aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads/Movies "$1"
}
 
Old 01-18-2012, 09:36 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
"unexpected end of file" errors mean that the shell found the opening character(s) for a command grouping, but didn't find the corresponding closing syntax. It reached the end of the file first. This can mean quotemarks, brackets, if..fi, etc.

Note that these can be some of the hardest errors to find. If you're missing a closing quote on a command, for example, it will treat the opening quote on the next command as the closer, and the one after that as an opener, etc, until it meets the final unmatched one at the end. You usually just just have to keep hunting until you find the mistake.

In this case though, your problem is with your function syntax, as CTM pointed out. The closing bracket needs to be separated from the contents by a command separator, which can be either a newline or a semicolon. So this should work as well:

Code:
function put(){ aria2c --timeout=60 --max-connection-per-server=4 --http-user=[myusername] --http-passwd=[mypassword] --dir=/media/downloads $1 ;}
 
1 members found this post helpful.
Old 01-18-2012, 09:58 AM   #4
CTM
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 308

Rep: Reputation: 287Reputation: 287Reputation: 287
+1 to David for an excellent explanation.
 
Old 01-19-2012, 11:03 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Oh yeah, I should also point out that the correct form for a function is one or the other of these:

Code:
function name { contents ;}
name() { contents ;}
So you shouldn't use both "function" and "()" at the same time. bash will accept it without error, but it's not proper. Indeed, the function keyword itself is a bash extension, and only the second pattern is fully portable.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Error: Unexpected File End Ripowal Programming 13 09-20-2011 12:44 AM
[SOLVED] source bashrc -> syntax error: unexpected end of file xri Slackware 25 01-12-2011 12:36 PM
[SOLVED] syntax error: unexpected end of file adidoosh100 Programming 14 08-08-2010 12:44 AM
why i get syntax error: unexpected end of file ?? freephys Linux - Newbie 3 06-24-2010 09:03 AM
syntax error: unexpected end of file ygdrazil Linux - Newbie 3 07-23-2009 05:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration