I’m starting with bash at university, anyone has any idea how to solve that problem:
Show first 5 files for each directory from $PATH variable, if some directory doesn’t exist, don’t show error message.
Solution can be something like:
ls -a ``echo $PATH | sed "s/:/ /g"`` 2> /dev/null
it works, maybe there exists other option but I don’t know how to limit results by 5 per each show block?
Try the following code :
${PATH//:/* /}part use bash parameter expansionprintf '%s\n'is printing any words separated by spaces on newlines/bin/ls -1list files on newlines. I puts the full PATH to override the aliashead -5print the first 5 linesedit
This is another solution using
perlwith a formatted output :Output example :