can't get stdout to a variable <p>it seems silly... I don't know what I am doing wrong....</p> <p>I need to change the .txt files encoding to utf-8. here the script:</p> <pre><code>#!/bin/bash for NOME_ARQ in *.txt do ##1 - verify file encoding and store in CODIFICACAO CODIFICACAO=$(file --mime-encoding "$NOME_ARQ" | cut -d" " -f2) ##2 - convert to utf-8 iconv -f "$CODIFICACAO" -t utf-8 "$NOME_ARQ" -o temp01.txt done </code></pre> <p>Have tried several ways for the ##1, but always get the following error:</p> <pre><code>sc-sini2csv: line 5: sintax error near `token' unexpected `CODIFICACAO=$(file --mime-encoding "$NOME_ARQ" | cut -d" " -f2)' sc-sini2csv: line 5: `CODIFICACAO=$(file --mime-encoding "$NOME_ARQ" | cut -d" " -f2)' </code></pre> <p>We see from the error, that the problem occur when assigning the variable $CODIFICACAO</p> <p>As far as I've looked around there are 2 ways of assigning the STDOUT to a variable:</p> <p>1- using backtick:</p> <pre><code>CODIFICACAO=`file --mime-encoding "$NOME_ARQ" | cut -d" " -f2` </code></pre> <p>or</p> <p>2- using $():</p> <pre><code>CODIFICACAO=$(file --mime-encoding "$NOME_ARQ" | cut -d" " -f2) </code></pre> <p>Both of them will give the same error. </p> <p>As I wrote, it seems silly, but I'm stucked on this error..... any hel will be much appreciated !!! </p> <p>PS: using $() or backticks directly from terminal (outside a bash script) will work.... but i need it into a shell script.</p> <p>In time: I'm using ubuntu with bash shell</p> <p>Thanks in advance !!! Silvio</p>