2

Is there a unix/linux utility, perhaps a shell builtin or an external command, that will limit the number of bytes placed into a bash variable? For example, I want to make sure STRING gets at most 1000 bytes (or some arbitrary number I choose) from the output of the curl (or other) command:

STRING=$(curl -s http://localhost:8010/status?)

Let me edit this to make clear that I'm just using curl as an example, but I'd like this to work with any command.

1 Answer 1

4

Just add -r 0-1000 to your curl commandline, i.e.:

STRING=$(curl -r 0-1000 -s http://localhost:8010/status?)

Or generically you can use head -c 1000, i.e.:

STRING=$(curl -s http://localhost:8010/status? | head -c 1000)
3
  • Ok thanks. But I'm looking for something more generic that will work with any command. Apr 19, 2016 at 0:44
  • Why not use the native argument in curl?
    – HTTP500
    Apr 19, 2016 at 0:45
  • because I don't want to restrict it to curl Apr 19, 2016 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .