Given a file test.txt
, with the content This is a test.
I want to extract a substring of its content, more specifically the second and third character ( hi
), using the command
echo ${$(cat test.txt):1:2}
However, this outputs the second and third word ( is a
) instead of the single characters.
I can do
a=$(cat test.txt)
echo ${a:1:2}
And it works as expected. But I want to do it in a single command.
Can someone explain what's happening here and offer a solution?
Edit:
The system is running zsh.