0

I have written a little script in Python that I use to append text to a work log. I have placed the script in a directory in my $PATH

#!/usr/bin/python

# import necessary modules
import sys
import os
import datetime


# main() function
def main():
  now = datetime.datetime.now()

  tmp = ' '.join(sys.argv[1:])

  outfile = '/path/to/output/done.log'

  outstr = now.strftime("%Y-%m-%d %H:%M:%S") + ' - ' + tmp + '\n'

  f=open(outfile,'a')
  f.write(outstr)
  f.close()

  # print sys.argv[0:1]
  print 'Adding ' + outstr

# Call main()
if __name__ == '__main__':
  main()

When I run the script as in example 1, I get an error.

Example 1:

host:scripts user$ done this is a test
-bash: syntax error near unexpected token `done'

If I run the script as in example 2, it behaves as expected.

Example 2:

host:scripts user$ python done this is a test
Adding 2012-11-15 09:57:44 - this is a test

How do I get this to work in the first example?

1 Answer 1

4

done is a bash keyword, so can't be used in certain places like "the place Bash expects a command name". You could use ./done (or /path/to/done, or python /path/to/done), or re-name the command.

Sign up to request clarification or add additional context in comments.

1 Comment

Very nice! If I rename the script to "cow" it works perfectly... now to find a verb that means complete...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.