If you need to write a bash script that loop thru directory, then here’s the solution. While writing this bash script to loop thru directory files, i learn something more about single and double quote. So make sure you dont add any double quotes or single quotes to your path when you follow the tutorial below.
To loop thru directory files in bash shell, follow the steps below:-
Advertisements
- Save the code below as file.
FILES=(/home/username/*) for f in "${FILES[@]}" do # FNAME is the only the file name without path # FNAME=`basename $f` # $f store current file name with path echo "Processing $f file..." done - Change “/home/username” to your own path
- Change the file permission to 700 or 755
- Execute the script and you will be able to loop thru the directory files
Related posts:
How to reload .bash_profile in Linux or Mac?
CentOS: install yum fastest mirror plugin for faster connection update
How to downgrade to PHP 5.2 using MacPort
Symfony Filter: Change ForeignKey drop down to Text field
Word cannot start the spelling checker - Word 2011
How to clear print queue in Mac?
How to hide apache2 version number in error page
How to flush DNS cache in Linux / Windows / Mac
Share this with your friends:-