This is quite simple in Python. You can start the interactive interpreter by just typing python and do something like this:
>>> open("test.bin", "wb").write("\4\4\4\7\7\32\32\32\32\32")
'wb' means "open the file for writing binary data to it", merely opening the file with w will assume you want to write text to it.
Note these are octal numbers (\32 is 0x1a, or 26)! They can also be hexadecimal (\xff), and you can save some typing by doing something like this:
>>> "\x00" * 4 + "\x09"
'\x00\x00\x00\x00\x09'
The normal operator precedence applies.
For more data, you can use lists of decimal integers - which I find easier to read and type:
>>> d = [1, 2, 3, 4, 5]
>>> ''.join(chr(i) for i in d)
'\x01\x02\x03\x04\x05'
If you prefer using python3, you'd use bytes() like this:
>>> bytes([1, 2, 3, 4, 5])
Of course 'arithmetic' works as you would expect:
>>> [1, 2, 3] * 2 + [9] * 4 + range(4)
[1, 2, 3, 1, 2, 3, 9, 9, 9, 9, 0, 1, 2, 3]
>>> range(10, 0, -3)
[10, 7, 4, 1]
Binary, orcal and hexadecimal literals are written like this:
0b1100 == 0o14 == 12 == 0xc
(Or 014 if you prefer)
If you want to do some complicated stuff, open the file first and then gradually write to it:
>>> f = open("test.bin", "wb")
>>> f.write("\xff" * 100)
>>> for i in range(10):
... f.write("\xff\xfa\x03")
...
>>> f.close()
And if you want to script it, you can use the -c switch to invoke the code directly from the command line:
python -c "open('test.bin', 'wb').write(''.join(chr(i) for i in [1, 2, 3]))"