turn file into byte array in bash

Posted on 2013-06-06
Last Modified: 2013-06-06
is there a way to turn a file into a byte array in a bash setting?
Question by:Evan Cutler
LVL 29

Assisted Solution

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

Open in new window

LVL 23

Accepted Solution

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

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

Open in new window


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.

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now