Mike Leone on 23 Apr 2010 11:35:48 -0700 |
So I'm trying to run the bash script JP posted the other day, and it's failing, for reasons I can't quite figure out. $ bash -n snag-files.sh 'nag-files.sh: line 15: syntax error near unexpected token `{ 'nag-files.sh: line 15: `function _file_size { Here's a snip of the file: ================= #!/bin/bash TREE='/ftp-area/' # Must be read-write by user LAST_RUN="$HOME/snag_files.last_run" # Must be writable by user SLEEP_SECS='5' # Wait between file checks. # If you have a lot of files to process, this will add up fast... ZIP_FILE="$HOME/snagged_$(date '+%Y-%m-%d_%H:%M:%S').zip" MAX_ZIPS_TO_KEEP='5' # Keep this many previous ZIP files, just in case #---------------------------------------------------------- # Define functions #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ function _file_size { # "Utility" function to return file size # Called like: now=$(_file_size "$file") # Returns: file size # We've already made sure the file exists and is readable, so... local file="$1" \ls -s "$file" | cut -d' ' -f1 } # end of function _file_size ================= Seems to think that the function declaration is invalid. Looks right to me, from what I can tell. However, even the sample script using functions fails: (<http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-8.html>) ================= $ more test.sh #!/bin/bash function quit { exit } function hello { echo Hello! } hello quit echo foo $ sh test.sh test.sh: 2: function: not found ============== So why are functions not being recognized on my system? Ubuntu 8.04. The shell for this user is explicitly set to "/bin/bash" in /etc/passwd. ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|