This post is new learning experiment on Internal Field Separator IFS. It is more efficient than tr command.By default IFS is available in the bash shell with ' ' space as delimiter which we could use directly in the scripts. This page contains two different experiments:
The following example will illustrate the variations
#!/bin/bash # Description : Script to illustrate the IFS usage clear echo -e "\nInitially..." echo mystring="vybhava:Technologies Trainings Consulting Development" for word in $mystring; do echo "Word: $word" done # Now lets apply the IFS echo -e "\nApplying IFS=\":\" ..." echo IFS=":" for word in $mystring; do echo "Word: $word" done echo -e "\nApplying IFS=\": \" ..." echo IFS=": " for word in $mystring; do echo "Word: $word" doneExecution of the above script gives us the follows:
Now in the cloud and virtualization era we need lots of automation strategies to save time and cost, where we need to develop such scripts which can be more effective and optimized scripts.
Here is sample remote domains.txt file
vybhava.biz:192.168.33.100:/home/oracle/logs:wladmin mydev01.com:192.168.33.1:/home/oracle/logs:ftpuser mydev02.com:192.168.33.2:/home/oracle/logs:ftpuser mydev03.com:192.168.33.3:/home/oracle/logs:ftpuser
#!/bin/bash # # Date : 31/01/2016 # Description : This sample IFS usage code help you to understand FTP Log files to remote box # file=domains.txt # set the Internal Field Separator to : IFS=':' while read -r domain ip logpath ftpusername do echo -e "*** Connecting to $domain ..." echo -e "Using $ip ip for process..." echo -e "Log path is set to $logpath" echo -e "Adding ftp access for $domain using $ftpusername ftp account...\n\n" done < $file
Execution of the above script as follows: