Shell commands not working when grouped in a bash script

robert

I have this file:

file.txt:
  4003f0:   48 83 ec 08             sub    $0x8,%rsp
  4003f4:   e8 73 00 00 00          callq  40046c

I am trying to extract the opcodes from the middle. First I search the first element after the opcodes (sub and callq):

get_asm_index.awk: 
BEGIN {
    i_min = 1000000;
}

{
    i = match($0, /[^ :0-9a-fA-F]/)
    if(i < i_min)
        i_min = i;
}

END {
    print i_min;
}

After that I print the opcodes:

get_hexdump.awk:
{
    i = match($0, /[:]/);
    print substr($0, i+1, i_min-i-1);
} 

Everything is working if I call the two awk files separately, but I get the following error when I group them in a shell script:

./do.sh: line 4: 48: command not found

The shell script:

do.sh:
#!/bin/bash
i_min=$(awk -f get_asm_index.awk file.txt)
$(awk -v i_min="$i_min" -f get_hexdump.awk file.txt)
Eric Renouf

Don't put the last command in $(). That will take stdout of the command within and put that in place of whatever is outside. So it could be used as value to set in a variable as in your line above, or it could be the spot where a parameter goes in a command line. In this case, you don't have anything else there, so you end up putting it in the spot where a command would go, and then the shell tries to execute it as a command.

In this example, it tries to execute 48 which is generally not going to be the name of a command.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Defined bash commands not found when passed in "do shell script" in osascript

root shell bash commands not working

Bash script commands not working in cron

Some commands not working in bash script

Commands Working In Terminal, But Not In Bash Script

CD $Variable not working when used in a (Bash) Shell Script

Skip shell commands when script is executed by Ansible

test on 'null' in bash/shell script not working

Awk print is not working inside bash shell script

line of code not working inside bash shell script

How to execute commands in docker container as part of bash shell script

bash script starting new shell and continuing to run commands

Bash (or other shell): wrap all commands with function/script

Wrap all commands entered within a Bash-Shell with a Python script

Why does this shell script fail in bash, but the commands work in SSH?

bash - Shell script opening multiple terminals and executing distinct commands

How to execute shell commands in a loop from within a bash script?

Flask Shell Commands not working

Undefined module when commands are grouped

Shell script and sed commands

Commands not found in shell script

channelExec.setCommand() Not Working when executing shell commands

Run shell script/commands when starting flask development server

Restrict kill commands when running jar file using a shell script

Script not working when passed to bash via -c

Commands in batch script not working

Bash Commands not working on Mac

Optional commands for bash script

Pass commands to Mongo shell from bash script without halting interactive Mongo shell