I want to retrieve the total number of files within a folder.
I would do this with
ls | wc -l.
My code is:
cd /home/user/myfolder num=$("ls | wc -l")
But I understand this opens a new shell which doesn't know that the working directory was changed. How can I execute the
ls | wc -l command within the same shell?