I'm trying to assign a variable using another variable that is being read in from a while and also being parsed at the same time. However, for some reason I'm not able to get the new variable to get the data i want. Any help would be appreciated.
while read line
do
foldername=$($line | awk -F'/' '{ print $4 }')
echo $foldername
done < folderlist.txt
folderlist.txt contains a list of directory where i'm trying to read the 4th parameter.
$line | awk -F'/' '{ print $4 }'alone is wrong. You shouldecho "$line" | awk -F'/' '{ print $4 }'orawk -F'/' '{ print $4 }' <<< "$line". Also, if you are getting the filename you can consider usingbasename $line.