LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 06-04-2005, 07:36 AM   #1
atom
Member
 
Registered: Feb 2004
Location: Slovenia
Distribution: archlinux
Posts: 271

Rep: Reputation: 31
Trivial bash question - executing $COMMAND


I'm making a recoding script, and i'm having trouble executing a command. Let me serve you the part of the script first:

Code:
COMMAND="lame $LAME_ARGUMENTS --tt \"$TITLE\" --tl \"$ALBUM\" --ta \"$ARTIST\" --ty \"$YEAR\" --tc \"$COMMENT\" --tn \"$NUMBER\" --tg \"$GENRE\" \"$file\" \"$OUTPUT_FILENAME\"";

        echo -e "The file will be encoded with the following data:"
        echo -e "Title:                 $TITLE"
        echo -e "Track Number:          $NUMBER"
        echo -e "Artist:                        $ARTIST"
        echo -e "Album:                 $ALBUM"
        echo -e "Year:                  $YEAR"
        echo -e "Genre:                 $GENRE"
        echo -e "Comment:               $COMMENT"
        echo -e "Output Filename:       $OUTPUT_FILENAME"
        echo 'Command: '$COMMAND
        echo -e "---------------------------------------------------------------------------------"
        echo -e $DELAY_MESSAGE
        for ((i=$DELAY; $i>0; i--))
        do
                echo -en "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                echo -en "$i seconds left"
                sleep 1
        done
        echo ""
        $COMMAND
This is the output:
Code:
The file will be encoded with the following data:
Title:                  The Wings Of The Hydra
Track Number:           01
Artist:                 Therion
Album:                  Lepaca Cliffoth
Year:                   1995
Genre:                  Metal
Comment:                Encoded by Atom
Output Filename:        Therion - 01 - The Wings Of The Hydra.mp3
Command: lame --vbr-new -V 9 --add-id3v2 --tt "The Wings Of The Hydra" --tl "Lepaca Cliffoth" --ta "Therion" --ty "1995" --tc "Encoded by Atom" --tn "01" --tg "Metal" "01 - The Wings Of The Hydra.mp3" "Therion - 01 - The Wings Of The Hydra.mp3"
---------------------------------------------------------------------------------
Delaying for 5 seconds. Press ctrl+c to abort.
1 seconds left
lame: excess arg The
LAME version 3.96.1 (http://lame.sourceforge.net/)

usage: lame [options] <infile> [outfile]
Why doesn't it execute??? If I copy and paste the command echoed at the Command: field it executes oh-right.. Weird

Anyone able to help? Greatly appreciated!
 
Old 06-04-2005, 08:40 AM   #2
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
make a simple script which just says

COMMAND="what you cut and paste before"
echo $COMMAND
$COMMAND

just for fun.

You see, I think that script macros are limited to 255 characters ... you have 258(?) there.
Try shorter filenames.

Last edited by Simon Bridge; 06-04-2005 at 08:45 AM.
 
Old 06-04-2005, 07:21 PM   #3
atom
Member
 
Registered: Feb 2004
Location: Slovenia
Distribution: archlinux
Posts: 271

Original Poster
Rep: Reputation: 31
Found the problem, and it wasn't this one.

Lame does not do it's own commandline parsing, it just takes the *argc one by one. The *argc array wasn't being filled right because the whole commandline argument was one string, meaning it parsed the first one-word arguments ok, because it had to, but the moment it encountered a more-than-one-word argument, even though it was encased in "", it took the first word as the argument, the second as the in-file and the 3rd as the out-file. It then discarded the rest as unnececary arguments. When I passed the arguments like this:

lame $LAME_ARGUMENTS --tt "$TITLE" --tl "$ALBUM" --ta "$ARTIST" --ty "$YEAR" --tc "$COMMENT" --tn "$NUMBER" --tg "$GENRE" "$file" "$OUTPUT_FILENAME"

instead of passing them like this:

COMMAND="lame $LAME_ARGUMENTS --tt \"$TITLE\" --tl \"$ALBUM\" --ta \"$ARTIST\" --ty \"$YEAR\" --tc \"$COMMENT\" --tn \"$NUMBER\" --tg \"$GENRE\" \"$file\" \"$OUTPUT_FILENAME\""
$COMMAND

it worked.
 
Old 06-05-2005, 01:06 AM   #4
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
<slaps forehead> And I was looking right at it ...
If you want to run a command in shell you just type it out!
What time was it - oh 1:40am ... figures

It would also have worked if you'd done
lame $input1 $input2 $input3

I gave you the guff about no of characters because I was trying it out and it only worked for me if I reduced the number of characters to less than 256.

Well done for figuring it out.
 
Old 06-05-2005, 05:17 AM   #5
atom
Member
 
Registered: Feb 2004
Location: Slovenia
Distribution: archlinux
Posts: 271

Original Poster
Rep: Reputation: 31
Well I'm sure it wasn't that obvious... Till now I didn't know bash did commandline-into-separate-strings-that-stick-or-don't-stick-together parsing in commandline only... I thought it does that to every command, wether it is passed as a single string or an identical part-string. Apparently we have some shorthands here that I don't really like... Should I report it to bash'es bugzilla?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash Scripting - echo command question gbhil Programming 2 04-27-2005 08:27 PM
noobie bash command question SamerAdra Linux - Newbie 5 10-26-2004 03:42 AM
Newbie question about executing java command oldoldcat Linux - General 4 01-30-2004 02:15 AM
bash command question BajaNick Linux - Software 8 10-05-2003 08:56 PM
Trivial sound question kkempter Linux - General 3 03-03-2003 11:53 AM


All times are GMT -5. The time now is 10:14 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration