Solved

turn file into byte array in bash

Posted on 2013-06-06
3
1,478 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
3 Comments
 
LVL 29

Assisted Solution

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

Open in new window

:p
0
 
LVL 23

Accepted Solution

by:
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):
#!/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

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