I'm learning shell scripting and found a very confusing situation:
- I retrieve all contents of the current directory using
conteudo="$(ls)"
; - Issuing
echo $conteudo
prints to the terminal "data emptydirectories.sh media obb", that's ok; - Then the script must run
echo `expr index "$conteudo" " "`
, which prints zero to the terminal, what got me already confused, 'cause I expected it to print 4; - The the last command is
echo ${conteudo:0:1}
, which prints "d" in the terminal (clown face).
I want to understand why the character changes in the two situations. I first imagined that the quotation was interfering in the way the string is being processed, but haven't found anything about it, and changing the quotation use either makes no effect or returns errors.