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:
Arrow key not working in vi / vim - Mac OS
Disable iTunes auto start when iPhone, iPad, or iPod is Connected
How to empty Trash in Roundcube web mail - CPanel?
How to install flash player in Ubuntu
How to switch window within the same program in Mac OS X
How to sort drop down - Admin Generator - Symfony 1.4
How to block .log file using in .htaccess
How to create password protected zip file in Mac OS X
Share this with your friends:-