LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 04-13-2008, 02:17 AM   #1
klo_2k
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Rep: Reputation: 0
Execute command with spaces from variable in bash script


Does anyone know why the following script doesn't work?

Code:
#!/bin/bash
cmda='hd "The Simpsons.(19x15).avi"|head'
$cmda

cmdb="hd 'The Simpsons.(19x15).avi'|head"
$cmdb

cmdc='hd The\ Simpsons.\(19x15\).avi|head'
$cmdc
When I run it I get
Code:
hd: "The: No such file or directory
hd: Simpsons.(19x15).avi"|head: No such file or directory
hd: 'The: No such file or directory
hd: Simpsons.(19x15).avi'|head: No such file or directory
hd: The\: Invalid argument
hd: Simpsons.\(19x15\).avi|head: Invalid argument

The strange thing is that those commands are perfectly fine if I copy the text variable out and run it...

The reason for my question above is because I have a script that generates a command dynamically and puts that command in a variable for execution.


Thanks.
 
Old 04-13-2008, 02:37 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Let's start with what is the "hd" command.
 
Old 04-13-2008, 03:00 AM   #3
klo_2k
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Hex dump - just something I can run on the avi file I happen to be testing the command with.

If everything's working fine, it should output:
Code:
00000000  52 49 46 46 4e 04 f0 0a  41 56 49 20 4c 49 53 54  |RIFFN...AVI LIST|
00000010  32 01 00 00 68 64 72 6c  61 76 69 68 38 00 00 00  |2...hdrlavih8...|
00000020  ec a2 00 00 00 00 00 00  00 00 00 00 10 01 00 00  |................|
00000030  ba 74 00 00 00 00 00 00  02 00 00 00 00 00 00 00  |.t..............|
00000040  00 02 00 00 80 01 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  4c 49 53 54 74 00 00 00  |........LISTt...|
00000060  73 74 72 6c 73 74 72 68  38 00 00 00 76 69 64 73  |strlstrh8...vids|
00000070  58 56 49 44 00 00 00 00  00 00 00 00 00 00 00 00  |XVID............|
00000080  40 42 0f 00 58 d8 6d 01  00 00 00 00 ba 74 00 00  |@B..X.m......t..|
00000090  a8 51 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |.Q..............|

Last edited by klo_2k; 04-13-2008 at 03:01 AM.
 
Old 04-13-2008, 03:31 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Code:
cmda='od default\ test.avi|head'
jschiwal@hpamd64:~> eval $cmda
0000000 000000 131401 000430 011440 177777 041342 040020 040100
0000020 040100 040100 040100 040100 040100 040100 040100 040100
*
0000100 040100 040100 040100 040100 040100 040100 000000 131001
0000120 103400 106561 000201 100667 022400 067145 067543 062544
0000140 020144 074542 052040 050115 042507 061556 024040 062566
0000160 027162 031040 032456 027070 032064 030456 031065 000051
0000200 000000 134001 004000 040000 000000 000001 007400 174377
0000220 000000 000401 171013 000773 053224 015445 072022 001503
0000240 076112 105276 161224 050203 160576 165367 145175 133746
 
Old 04-13-2008, 03:59 AM   #5
klo_2k
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks! eval did the trick.
 
  


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
Perl:Not able to execute command in variable jags.singh Programming 1 07-23-2007 08:51 AM
bash script with spaces Quantum0726 Programming 2 11-14-2005 10:26 PM
bash script ? -- spaces in passed parameters azwr Linux - Newbie 3 06-18-2004 07:57 PM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 10:22 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 02:45 AM


All times are GMT -5. The time now is 08:57 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