I am trying to get a list of only directory names in order to store it in a variable for a foreach for processing later on.
However, just testing the ls
first I am getting weird results.
For example:
ls -1 /var/lib/mysql/ | grep -e '^d'
db_nagiosql
db_nagiosql_v32
discount-o-matic
drupal
drupal5
However, this does what it should do:
ls -l /var/lib/mysql | grep -e '^d' | awk '{print $9}'
alex
bugs
bugtracker
bugzilla
cacti
cerb5
db_nagiosql
db_nagiosql_v32
discount-o-matic
drupal
drupal5
earth
fft
final_function_test
firm_ware
flyspray
gallery2
graphics
jon
joomla
mysql
nconf
old_fft
opendocman
oreon
part-number
phpbb
phpbugtracker
phplist
postnuke
teldir
test
testing
vanilla
vision
wikidb
wordpress
zen
The issue is, I need this to be portable(ish) so the awk part I rather not have as it may not always be the ninth column. Why does the ls -1
not work while the ls -l /var/lib/mysql | grep -e '^d' | awk '{print $9}'
does work?