I am facing some minor problems when coding linux shell scripts.
My codes are below and I am struggling to input my modified string names to the variable named "fileName" as shown in below. And then, I commanded echo to identify the previous code is working well. However, it outputs nothing.
How to resolve this issues?
for file in ./*.txt
do
fileName=$file | rev | cut -d. -f2 | rev
echo {$fileName}
done
As I said, echo{$fileName} didn't output the words that I wanted to extract.
I look forward to your helpful advice :)
fileName, you need something likefileName=$(echo "$file" | rev | cut -d. -f2 | rev). This echoes the value in$fileto the sequence of commands and captures the output in the variable. In Bash, you could use a here string instead ofecho.