I'm trying to write a simple bash script that accepts all arguments and interprets them simply as a string.
In other words:
tweet Testing out my command-line tweetings. #commandlinetweets
Takes in all the arguments and just uses them bluntly as a string.
Here is the basic form that I have at the moment:
function tweet()
{
echo "Tweeting using curl."
curl -u tchalvak "http://twitter.com/statuses/update.xml" -d status="$@"
echo "Tweet done if spammed info back above."
echo "Tweeted using username tchalvak with status $@"
}
Right now the erroneous result of running the function is:
$ tweet TEst again and again and again.
Tweeting using curl.
Enter host password for user 'tchalvak':
<?xml version="1.0" encoding="UTF-8"?>
<hash>
<request>/statuses/update.xml</request>
<error>Status is a duplicate.</error>
</hash>
curl: (6) Couldn't resolve host 'again'
curl: (6) Couldn't resolve host 'and'
curl: (6) Couldn't resolve host 'again'
curl: (6) Couldn't resolve host 'and'
curl: (6) Couldn't resolve host 'again.'
Tweet done if spammed info back above.
Tweeted using username tchalvak with status TEst again and again and again.
So how do I get from multiple arguments to "all these technically multiple arguments should be counted as just one string variable inside the function"?
Edit: Sorry, I should clarify that I figured I'd just hardcode the username for maximum bulletproofing of the tweeting syntax.
Final solution (as long as you ignore command interpretation issues like #
hashes not coming through and similar problems that this dirty method is going to cause, heh):
function tweet()
{
STATUS="$*"
echo "Tweeting using curl."
curl -u tchalvak "http://twitter.com/statuses/update.xml" -d status="$STATUS"
echo "Tweet done if spammed info back above."
echo "Tweeted using username tchalvak with status $STATUS"
}