Bash Concatenating Strings Improperly -


i have text file list of mercurial repositories in it, in form:

ide install installshield 

i'm writing bash script clone/pull/update repositories based on text file. right i'm echoing before actual cloning. if do:

while read line;     echo "hg clone" ${master_hg}/${line}; done < repos.txt 

the output expected:

hg clone /media/fs02/ide hg clone /media/fs02/install hg clone /media/fs02/installshield 

however, if do:

while read line;     echo "hg clone" ${master_hg}/${line} ${reporoot}/${line}; done < repos.txt 

the output is:

/var/hg/repos/ide02/ide  /var/hg/repos/installnstall /var/hg/repos/installshieldshield 

it seems replacing beginning of string end of string. there kind of character overflow or going on? apologies if dumb question, i'm relative noob bash.

your file has dos line endings; \r @ end of $line causes cursor return beginning of line, affects output when $line not last thing being printed before newline. should remove them dos2unix.


you can use similar perl's chomp command remove trailing carriage return, if 1 present:

# $'\r' bash-only, easy type. posix shell, you'll need find # someway of entering ascii character 13; perhaps control-v control-m line=${line%$'\r'} 

useful if, whatever reason, can't (or don't want to) fix input before reading it.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -