The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
variable part of variable name Smoker Shell Programming and Scripting 2 01-25-2008 01:11 PM
Repacing part of string with a variable divz Shell Programming and Scripting 4 07-19-2007 01:09 AM
New & could use some direction! LazySpoon UNIX for Dummies Questions & Answers 2 03-19-2007 04:48 AM
ksh: A part of variable A's name is inside of variable B, how to update A? pa3be Shell Programming and Scripting 4 03-30-2005 11:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-06-2007
peterloo peterloo is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
direction symbol in a variable as part of the command

Hi,

How can I get this to work?

#!/bin/ksh

if [ -n "$1" ]; then
direction=">>"
else
direction=">"
fi

cat some_file_name $direction temp.txt

exit

This shell script is not happy with using "$direction" opposed to ">" or ">>".

Thanks.

Peter
  #2 (permalink)  
Old 12-06-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Try

direction=\>

maybe, just maybe...
  #3 (permalink)  
Old 12-06-2007
peterloo peterloo is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
Nope it did not work. When I echo it out, it shows "\>". I tried using eval, but with eval, I can get the return code if there was a problem with the command.
  #4 (permalink)  
Old 12-06-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
eval is the key to getting this work and I do not understand your objection. You can ignore the return code if you want. Or you can test it if you want. This is the way any command works.


Code:
$ eval true
$ echo $?
0
$ eval false
$ echo $?
1
$
  #5 (permalink)  
Old 12-06-2007
peterloo peterloo is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 3
You are absolutely correct. I don't know what I did, but it did not work earlier. Thanks for your help.
  #6 (permalink)  
Old 12-06-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
An alternative would be to run shell again...

Code:
sh -c "cat some_file_name $direction temp.txt"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0