Please explain how this Read Command works
Hi All,
I am new to linux and I am finding difficulties in understanding the below commands. Please explain what is happening in the below commands. Code:
IFS="~" Please explain how this commands flows especially exec 4< $BCP_DIR/cnts.data & exec 4<&- |
Please read the REDIRECTION section of 'man bash'.
|
In fairness, there is some rather uncommon stuff in that script. Let's break it down:
Code:
IFS="~" Code:
exec 4< $BCP_DIR/cnts.data Code:
while read -ru4 TableName Count CreationDateTime Type AccessDate Code:
. /apps/rmb/prod/scripts/load_datasum.ksh Code:
IFS=" " Code:
exec 4<&- |
Quote:
Normally, in order to restore IFS, another variable that takes the value of IFS should be declared. Code:
oIFS=$IFS |
Quote:
And of course if the script ends at that point, there wasn't really any need to restore IFS at all. |
Quote:
Quote:
|
Quote:
|
Hi rknichols,
Thanks Very Much for the detailed explanation. I now understood it clearly :D Hi vincix, Thanks for the suggestion .... ;) Quote:
This is a real world scenario, I just posted where im getting doubt. The functioning of the script is to weekly load the bulk data coming from Downstream to MSSQL Database tables using this script. The files mentioned in the post contains the information of the counts of data being inserted. I am new to Linux field, that's why Im facing difficulties in Understanding the commands. Now I see this command in the same script . Please explain what this below command does and also advise any book or online tutorial for learning Shell commands. Code:
if [[ -f $BCP_DIR/clmcldt.data ]] |
Try reading these, and more importantly actually start writing small scripts; there's no substitute for experience - guides are just that.
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ there are a million bash guides on the net .... The only exotic bit of that script is calling the 'ed' editor as a cmd instead of interactively - an odd way to do it ... |
Actually the script is written for the Korn shell (ksh). Note the sourced file in post #1 (load_datasum.ksh) and the use of print in post #8.
The code is testing for the presence of a file $BCP_DIR/clmcldt.data. If the file exists, the ed editor is being used to remove all spaces in the file. The edits are being logged to the file $LOG_DIR/load_clmcldt.edit.log The actual ed commands are: H - Turn on descriptive errors g/ /s///gp - Globally search for lines containing a space and replace with nothing for every occurrence of space in the line, printing the line when substitutions occur w - write the resulting file q - quit |
Thanks chrism01 and Allen for explanation ... !!
|
All times are GMT -5. The time now is 10:25 AM. |