As long as the limits of your command-line handling code (e.g., bash
or ruby
itself) are not exceeded, you should have no technical problems in doing this.
Whether it's a good idea is another matter. Do you really want to have to type in a couple of hundred kilobytes every single time you run your program? Do you want to have to remember to put quotes around your data if it contains spaces?
There are a number of ways I've seen this handled which you may want to consider (this list is by no means exhaustive):
Change your code so that, if there's no arguments, read the information from standard input - this will allow you to do either
ruby somescript.rb myData
or
ruby somescript.rb <myFile.txt
.
Use a special character to indicate file input (I've seen @
used in this way). So,
ruby somescript.rb myData
would use the data supplied on the command line whilst
ruby somescript.rb @myFile.txt
would get the data from the file.
My advice would be to use the file-based method for that size of data and allow an argument to be used if specified. This covers both possible scenarios:
- Lots of data, put it in a file so you won't have to retype it every time you want to run your command.
- Not much data, allow it to be passed as an argument so that you don't have to create a file for something that's easier to type in on the command line.