(This answer is obsolete as of the Minecraft 1.20.5 update)
This answer is for 1.13-1.20.4 See my other answer for the syntax for 1.20.5 and later.
The syntax for enchanted items has changed a bit in 1.13, meaning the accepted answer no longer works.
- The
ench
tag has been renamed toEnchantments
- The
id
field of an enchantment is now a string, rather than an integer.
Thus, to give a player a diamond sword with Smite 2 and Knockback 30, one would now use:
/give @p diamond_sword{Enchantments:[{id:"minecraft:smite",lvl:2s},{id:"minecraft:knockback",lvl:30s}]}