LinuxQuestions.org
Visit Jeremy's Blog.
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 10-27-2004, 06:31 PM   #1
clsonnt
LQ Newbie
 
Registered: Jun 2003
Distribution: Redhat
Posts: 14

Rep: Reputation: 0
want to use Variable as commandline


I would like to be able to load a commandline into an environmnetal variable and then runn the command using that variable.

It seems to work OK until I get special characters in the commandline. For instance
Code:
REMOVECOMMAND="rm -f $DESTINATIONDIR/$SOURCEHOSTNAME/$TARFILENAME{,.gz}"
$REMOVECOMMAND
runs just fine!! But
Code:
BACKUPCOMMAND="tar -cf $DESTINATIONDIR/$SOURCEHOSTNAME $TARFILENAME $SOURCEDIRECTORY > $DESTINATIONDIR/$SOURCEHOSTNAME/$LISTNAME 2>>$MAILFILE"
$BACKUPCOMMAND
fails!

Looking at the results of "set -x" shows that the redirects are being put in single quotes.

I have tried using
Code:
eval $BACKUPCOMMAND
my "set -x" output looks like this:
Code:
+ eval tar -cf /data2/iwapps2/admin-nitely2.tar /usr/local/admin '>' /data2/iwapps2/admin-nitely2.ls '2>>/root/mailfile-local-nitely-admin'
++ tar -cf /data2/iwapps2/admin-nitely2.tar /usr/local/admin
+ OURCEHOSTNAME/admin-nitely2.ls
+ status=127
I have tried various varations of the eval command and none seem to work. Would appreciate any guidence.

THNX
 
Old 10-28-2004, 02:38 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
eval $variable where variable contain a command with redirections works for me.
Code:
pcjll:/tmp $ cat s
#!/bin/ksh
rm -f /tmp/out /tmp/err
a="date >/tmp/out 2>/tmp/err"
eval $a
ls -l /tmp/out /tmp/err

pcjll:/tmp $ s
-rw-r--r--   1 jlliagre  0 Oct 28 09:35 /tmp/err
-rw-r--r--   1 jlliagre 30 Oct 28 09:35 /tmp/out
 
Old 10-28-2004, 11:55 AM   #3
clsonnt
LQ Newbie
 
Registered: Jun 2003
Distribution: Redhat
Posts: 14

Original Poster
Rep: Reputation: 0
THNX....That lead me to what works!!!
 
  


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
X!! Fowarding using commandline cvcrud Red Hat 3 06-26-2005 04:22 PM
Remote CommandLine moejoe Linux - Networking 1 12-28-2004 10:40 AM
using mcrypt from commandline Hano Linux - Security 5 12-11-2004 09:17 AM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 03:19 AM
Commandline Handbook SloHands General 11 01-31-2003 01:38 PM

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

All times are GMT -5. The time now is 08:33 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
Open Source Consulting | Domain Registration