[opensuse] How to call a script for all files in a directory?
Hi how can a bash script look up the contents of a directory and call another script for all files within this directory? It would be great to have those files sorted by name or create-date first before the names get thrown at the second script. Filenames are like this Export-YYYYMMDD -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday, 2013-09-24 at 00:01 +0200, Andreas wrote:
how can a bash script look up the contents of a directory and call another script for all files within this directory?
Find pipe xargs, for instance. Or find /path/ -type f -exec command '{}' \;
It would be great to have those files sorted by name or create-date first before the names get thrown at the second script.
Playing with find and sort, perhaps. - -- Cheers, Carlos E. R. (from 12.3 x86_64 "Dartmouth" at Telcontar) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlJA2LAACgkQtTMYHG2NR9VE+ACeKgsqCSSsOCvj5g45/lXvugwr zDwAn3jcEvVpX03jC+1dTUr46tvFX36d =zWq7 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Monday 23 Sep 2013 23:01:53 Andreas wrote:
Hi
how can a bash script look up the contents of a directory and call another script for all files within this directory? It would be great to have those files sorted by name or create-date first before the names get thrown at the second script.
Filenames are like this Export-YYYYMMDD
Example: This first bash script is the one being called and passed the file name - - - - -8< - - - - - - - ~/prt.sh - - - - -8< - - - - - - - #!/bin/bash echo "Filename: $1" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This is the control script, that cycles through the files found and calls the other script... - - - - -8< - - - - - - - ~/list.sh - - - - -8< - - - - - - - #!/bin/bash for f in `find ~/ -maxdepth 1 -type f -name "*.txt" | sort`; do ~/prt.sh $f done - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Output... $ ./list.sh Filename: /home/ritchie/Export-20120601.txt Filename: /home/ritchie/Export-20130703.txt $ -- Ritchie -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (3)
-
Andreas
-
Carlos E. R.
-
Ritchie Fraser