Why statement works in LINUX and not UNIX?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why statement works in LINUX and not UNIX?
# 1  
Old 10-29-2013
Why statement works in LINUX and not UNIX?


I have a ksh script that uses code below. For some reason it works under linux but fails in unix. Any idea why?
if [[ "$instance" =~ "DEV" ]]; then ...

# 2  
Old 10-29-2013
Post the respective shell versions.
# 3  
Old 10-29-2013
=~ is BASH-only syntax, and only very new versions of BASH at that.

Most shells will let you do if [[ "$instance" == *DEV* ]] however.
This User Gave Thanks to Corona688 For This Post:
# 4  
Old 10-29-2013
Thanks guys,
My linux bash version is
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

For unix, I can't even find one. I tried
bash --version

which bash

/bin/bash --version

When I do
man bash

it gives me No manual entry for bash. Is it possible that I do not even have one.
# 5  
Old 10-29-2013
Yes, bash is a GNU program and is typically not installed on unix systems. ksh is quite similar and is a good alternative but some bash features will not be available (checkout this Bash/KSH Protability Issues link for some things to look out for).

@(#)MIRBSD KSH R48 2013/08/16
$  [[ "dfjdkfDEVfjfj" == *DEV* ]] && echo yes

Last edited by Chubler_XL; 10-29-2013 at 07:10 PM..
# 6  
Old 10-29-2013
Originally Posted by rdogadin
For unix, I can't even find one.
BASH is not the only shell in the universe, or even the only Bourne shell. sh is the ancestor of ksh and bash, which have different extended features on top of ordinary sh but remain mostly compatible with ordinary sh code.

bash incorporates many features of ksh, the == syntax I showed earlier being one of them.
# 7  
Old 10-30-2013
Thank you all for your replies. I guess one thing I am confused about is if I run my script under Korn Shell (#!/bin/ksh) on both unix and linux then why does it matter if I have BASH installed and what version of BASH I have?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Hardware

Does this hardware works with Linux

Hello folks, I pretend acquire this hardware: 1-Motherboard Asus Skt1151 - H110M-A/M.2 (https://www.asus.com/pt/Motherboards...cifications/); 2-Intel i5 6400 2.7Ghz QuadCore Skt1151; or 2-Intel i5 6500 3.2Ghz QuadCore Skt1151; 3-Dimm 8GB DDR4 Kingston CL15 2133Mhz; Obvious I pretend... (1 Reply)
Discussion started by: enodev
1 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

Script works with Linux not with Solaris

Hi I have the following script which works in Linux shell but gives issues with Sun OS Solaris 5.10, What i am trying to achieve here is we have a list of file names in list.txt file and we parse each file at a time for a particular pattern and copt next 4 lines after we hit the pattern to a... (6 Replies)
Discussion started by: Yugendra
6 Replies

4. Shell Programming and Scripting

sed works on Linux and Unix does not work

Hi, I use this command in Linux but if I run the same command does not work in freebsd. Follow the below command: Linux works: sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src' squid2.conf > squid.conf ; sed -e... (7 Replies)
Discussion started by: andreirp
7 Replies

5. Shell Programming and Scripting

awk -F works on Linux, but not on Solaris

Hello, I found this command works on Linux: $ echo `uptime` | awk -F "load average: " '{ print $2 }' 1.60, 1.53, 1.46 but got error on Solaris: $ echo `uptime` | awk -F "load average: " '{ print $2 }' awk: syntax error near line 1 awk: bailing out near line 1 $ which awk... (2 Replies)
Discussion started by: seafan
2 Replies

6. Programming

question about how the if statement works

on C programming, on an if statement, if u have something like if A && B && C { } if A is false, will it still move on to B and check it? (1 Reply)
Discussion started by: omega666
1 Replies

7. Shell Programming and Scripting

Issue with script in linux but in unix works

I have this simple script: #! /usr/bin/sh #***************************************************************************** # *** get_input (question variable) *** #***************************************************************************** get_input () { echo "${BOLD}${1} : " read... (14 Replies)
Discussion started by: C|KiLLeR|S
14 Replies

8. Programming

fcntl works in linux but not in mac os x

Hi, Unless I am missing some serious differences in Mac and linux in terms of C programming, I dont know why this would happen. Please take a look at the following piece of code fragment: bool add_input_to_db(Cons *new_data) { // Set the attributes of the lock struct flock fl =... (3 Replies)
Discussion started by: newhere
3 Replies

9. UNIX for Dummies Questions & Answers

what's the Linux|Unix OSes works on Servers

Hi everybody , I'm new here in the forum and new Dummy in L|U systems (Hope finding welcomes...:)). I just want to ask : What is the OS's that works on servers and the OS's that work as client OS?? I just know that Solaris Work on sarvers :D.. and i'm glad to be memmber in this... (1 Reply)
Discussion started by: derbi
1 Replies

10. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (0 Replies)
Discussion started by: Silverhood
0 Replies
Login or Register to Ask a Question