?
Solved

turn file into byte array in bash

Posted on 2013-06-06
3
Medium Priority
?
1,818 Views
Last Modified: 2013-06-06
Greetings,
is there a way to turn a file into a byte array in a bash setting?
Thanks
0
Comment
Question by:Evan Cutler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 600 total points
ID: 39226744
$ man od
$ od -c MyFile >MyFile.dmp

Open in new window

:p
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 1400 total points
ID: 39227003
What do you mean by byte array?  A file is already an array of bytes. ;-)

Something like this (hex):
#!/bin/bash
filename=$1
bytearray=(`od -x $filename | cut -c9- `)
echo "bytes:" ${bytearray[@]}

Open in new window

0
 
LVL 9

Author Closing Comment

by:Evan Cutler
ID: 39227038
thanks. perfect.
I'm sending a zip file into a webservice using a curl from a bash script.

Just to add to the fun, it's not a file-upload.  it's a bytearray package in the soap message.  Fun.

That worked.
Thanks.
0

Featured Post

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Utilizing an array to gracefully append to a list of EmailAddresses
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question