BASH – [: too many arguments

August 23rd, 2010 by Xerxes Leave a reply »

I’ve been writing a little bash script to wrap up the functionality in the JIRA CLI, and i’d noticed that sometimes, my script was spitting out the following error:

sh.exe": [: too many arguments

The code in question was:

j () {
if [ -z $3 ]; then
echo jira --action progressIssue --issue "$1" --step "$2";
...
...

It turns out the problem was that the variable $3 in the second line was being substituted directly into the if statement, without being quote delimited. So Bash is treating any input in $3 with spaces as multiple arguments (hence the "too many arguments" error). Duh.

Solution is to quote the $3 variable in the conditional to treat it as a single argument. Shouldn't make this mistake again...

Bookmark this post:
  • DotNetKicks
  • DZone
  • TwitThis
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati

Related posts:

  1. e Text Editor: “ruby: no such file to load — ubygems (LoadError)” i’ve installed e text editor on my desktop and trying...
  2. Mounting NAS drive under Ubuntu I’ve been battling this one for a long time….Finally got...
  3. Making Resolving Conflicts in Git Easier One thing that bugs me when using Git, is that...
  4. Instant Twitter Bookmark Tonight’s been a busy night for silly coding This first...
  5. Scripting Google Chrome for OSX using AppleScript When it comes to software tools, i like to spend...

Comments are closed.