I have a filename with several underscores:
nc_glals_3_4.mrc
and there I can read out the values 3 and 4 with awk:
$ echo "nc_glals_3_4.mrc" | awk -F'[_.]' '{print$3$4}'
34
But if I like to store 34 as a variable and recall the variable, it does not work:
$ variable=$("nc_glals_3_4.mrc" | awk -F'[_.]' '{print $3$4}')
-bash: nc_glals_3_4.mrc: command not found
$ variable="$("nc_glals_3_4.mrc" | awk -F'[_.]' '{print $3$4}')"
-bash: nc_glals_3_4.mrc: command not found
$ variable
-bash: variable: command not found
What's wrong?
variable=$(echo "nc_glals_3_4.mrc" | awk -F'[_.]' '{print $3$4}')echoinside of$( . . . )just like on the outside. Bash is attempting to run your string as a program