The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 09:25 AM
Why generate "ash and bash" different output for same bash script? s. murat Shell Programming and Scripting 0 05-26-2008 04:19 AM
korn shell to bash - statement not working brdholman UNIX for Dummies Questions & Answers 5 10-15-2007 06:49 AM
Korn Shell gpanesar Shell Programming and Scripting 4 03-25-2005 02:46 PM
korn syntax sajjad02 Shell Programming and Scripting 1 09-27-2004 07:15 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-01-2001
Registered User
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
Korn vs Bash

Let's say I have
alias good_op=`[[ "$sign" = "+" || "$sign" = "-" ]]`
in a Korn shell script. How can I write that in a non-interactive bash shell?
Forum Sponsor
  #2  
Old 10-01-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Have you tried that in bash? Bash implements some of the cool features of ksh, so that entire statement (possibly even most of your script) very well may work in bash.
  #3  
Old 10-01-2001
Registered User
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
thanks, it didn't work in bash, but I found a way around:
using test, do, and done -
test [ "$sign" = "+" -o "$sign" = "-" ]; do...
not the most elegant, but it works.
  #4  
Old 10-02-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,664
I got your alias to work in bash. But when I do "bash --version", I get 2.03. I'm guessing that you are using an older version of bash.

The only feature that I miss in bash is the ksh co-process code. Once bash picks that up, I will probably switch to bash.
  #5  
Old 10-02-2001
Registered User
 

Join Date: Feb 2001
Location: San Francisco
Posts: 30
this is my version:
GNU bash, version 2.03.8(1)-release (i386-redhat-linux-gnu)
Copyright 1998 Free Software Foundation, Inc.

The alias will only work in an interactive shell. I get an interactive shell when I login, but any script that runs will start its own non-interactive shell.

Oh, this is bash2.
  #6  
Old 10-02-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,664
You're right. I tested interactively and I can't get bash to use aliases at all in a script. A more elegant work-around is to switch to functions. I think the existence of functions is why both ksh and bash have weak alias commands. The function is:

good_op() { [[ $sign = + || $sign = - ]] ; }

and yes, with the [[ command, you can drop all those double quotes you had.
Google The UNIX and Linux Forums
Closed Thread

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0