LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2011, 06:01 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
echo "Here I am in $var1 selling ties": does not do what I expect.


Bash 3.1.7

Hi:
Code:
#!/bin/bash

#         

file=$1
infile=$1".cue"
FIRST=1

while read A1 A2 A3            # TRACK 08 AUDIO
do
if [ "$A1" == "TRACK" ] 
then 
        read A1 A2             # TITLE "Piano ..........."
        read A1 A2 A3          # INDEX 00 40:18:43
#       echo $A3               # 40:18:43

        old="$new"
        new="$A3"
        if [ $FIRST == 1 ] 
        then
                FIRST=0
        else
                # Here new is 08:28:10
                echo "Here I am $new waiting"
        fi               
        echo ----------------
fi
done < "$infile"
echo "flac --skip="$new
exit
The output is
Code:
----------------
 waitingm 62:36:67
 until=decode --skip=53:40:73
----------------
 waitingm 65:53:13
 until=decode --skip=62:36:67
--
But it should be Here I am 08:28:10 waiting. I have tried in a thousand different ways and always 'waiting' overwrites the string. What am I doing wrong?

Part of the input file is
Code:
 TRACK 09 AUDIO
    TITLE "Piano Sonata No.19 in G minor, op.49 no.1 - II. Rondo. Allegro"
    INDEX 01 43:53:30
  TRACK 10 AUDIO
    TITLE "Piano Sonata No.20 in G major, op.49 no.2 - I. Allegro, ma non troppo"
    INDEX 00 47:21:58
    INDEX 01 47:29:33 # --> new
 
Old 07-07-2011, 06:37 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
It's probably because the file uses "\r\n" Windows line endings rather than "\n" Unix line endings and you're reading that \r into the var. As such, it is actually printing "Here I am 08:28:10\r waiting", and \r resets the cursor back to the start of the line (carriage return).
 
1 members found this post helpful.
Old 07-07-2011, 06:37 PM   #3
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 234Reputation: 234Reputation: 234
Well, it works here. I just saved your script to test.sh and the sample data to input.cue. I run it:

Code:
$test.sh input
----------------
Here I am 47:21:58 waiting
----------------
flac --skip=47:21:58
The only difference is that I'm running bash 4.1. Maybe that's the problem, but I'm not sure.
 
Old 07-07-2011, 10:05 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Lo and behold! The input file is a DOS style file. Diantre's suggestion turned out to be true!
 
Old 07-07-2011, 10:17 PM   #5
Diantre
Member
 
Registered: Jun 2011
Distribution: Slackware
Posts: 515

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by stf92 View Post
Lo and behold! The input file is a DOS style file. Diantre's suggestion turned out to be true!
Ehem! *cough*... It was actually @tuxdev who suggested it. Glad you got it working though.
 
Old 07-07-2011, 10:52 PM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
You are right.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to send the output of a command in a file defined by a eval $"$var1" toordog Programming 3 07-07-2010 04:26 PM
My "expect" script is not working... Won't "send" commands... edomingox Programming 4 04-02-2009 03:25 PM
bash: how to divide complex : FINAL=`[ ($var2 - $var1 ) / $var1 * 100 ]` frenchn00b Programming 9 11-06-2008 10:04 AM
LXer: "Selling" Linux - We've Been Doing it All Wrong LXer Syndicated Linux News 0 08-06-2007 05:46 PM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 02:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration