Bash: Use raw binary in variable as executable?
up vote
2
down vote
favorite
I'd like to create a variable containing binary data, then execute in a command. Example:
#!/bin/bash
var="$(cat /bin/sleep)"
"$var" 9999
linux bash shell ubuntu variable
New contributor
add a comment |
up vote
2
down vote
favorite
I'd like to create a variable containing binary data, then execute in a command. Example:
#!/bin/bash
var="$(cat /bin/sleep)"
"$var" 9999
linux bash shell ubuntu variable
New contributor
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'd like to create a variable containing binary data, then execute in a command. Example:
#!/bin/bash
var="$(cat /bin/sleep)"
"$var" 9999
linux bash shell ubuntu variable
New contributor
I'd like to create a variable containing binary data, then execute in a command. Example:
#!/bin/bash
var="$(cat /bin/sleep)"
"$var" 9999
linux bash shell ubuntu variable
linux bash shell ubuntu variable
New contributor
New contributor
New contributor
asked Nov 17 at 23:59
user321517
202
202
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
You cannot execute a variable like that because:
- the kernel executes files,
- the shell can execute command lines stored in variables, but it cannot interpret binary data
- storing a binary file's contents in a variable will likely not work well, because null bytes may be present in the file (and you can't have null bytes in variables of most shells)
- even if you used process substitution to get a temporary file with the contents of that variable, process substitution file handles won't be executable
So you'll have to store the contents in a file, make that file executable, hope that nothing got missed because of a null bytes, and execute that file.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You cannot execute a variable like that because:
- the kernel executes files,
- the shell can execute command lines stored in variables, but it cannot interpret binary data
- storing a binary file's contents in a variable will likely not work well, because null bytes may be present in the file (and you can't have null bytes in variables of most shells)
- even if you used process substitution to get a temporary file with the contents of that variable, process substitution file handles won't be executable
So you'll have to store the contents in a file, make that file executable, hope that nothing got missed because of a null bytes, and execute that file.
add a comment |
up vote
3
down vote
accepted
You cannot execute a variable like that because:
- the kernel executes files,
- the shell can execute command lines stored in variables, but it cannot interpret binary data
- storing a binary file's contents in a variable will likely not work well, because null bytes may be present in the file (and you can't have null bytes in variables of most shells)
- even if you used process substitution to get a temporary file with the contents of that variable, process substitution file handles won't be executable
So you'll have to store the contents in a file, make that file executable, hope that nothing got missed because of a null bytes, and execute that file.
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You cannot execute a variable like that because:
- the kernel executes files,
- the shell can execute command lines stored in variables, but it cannot interpret binary data
- storing a binary file's contents in a variable will likely not work well, because null bytes may be present in the file (and you can't have null bytes in variables of most shells)
- even if you used process substitution to get a temporary file with the contents of that variable, process substitution file handles won't be executable
So you'll have to store the contents in a file, make that file executable, hope that nothing got missed because of a null bytes, and execute that file.
You cannot execute a variable like that because:
- the kernel executes files,
- the shell can execute command lines stored in variables, but it cannot interpret binary data
- storing a binary file's contents in a variable will likely not work well, because null bytes may be present in the file (and you can't have null bytes in variables of most shells)
- even if you used process substitution to get a temporary file with the contents of that variable, process substitution file handles won't be executable
So you'll have to store the contents in a file, make that file executable, hope that nothing got missed because of a null bytes, and execute that file.
answered Nov 18 at 0:52
muru
35.1k581154
35.1k581154
add a comment |
add a comment |
user321517 is a new contributor. Be nice, and check out our Code of Conduct.
user321517 is a new contributor. Be nice, and check out our Code of Conduct.
user321517 is a new contributor. Be nice, and check out our Code of Conduct.
user321517 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482431%2fbash-use-raw-binary-in-variable-as-executable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown